#include <iostream> #include<cmath> #include<ctime> #include<string> #include <iomanip> #include <fstream> using namespace std; double avgOfEvenPlaces(int number); int reversal(int n); int main() { int number; cin >> number; cout << fixed<<setprecision(3)<<avgOfEvenPlaces(reversal(number)); } double avgOfEvenPlaces(int n) { int digit, count = 1.0, countOfEven = 0.0; double sumOfEven = 0.0; while (n != 0) { digit = n % 10; n /= 10; if (count % 2 == 0) { sumOfEven += digit; countOfEven++; } count++; } return sumOfEven / countOfEven; } int reversal(int n) { int digits, revers = 0.0; while (n != 0) { digits = n % 10; revers = revers * 10 + digits; n /= 10; } return revers; }
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter