Untitled
unknown
plain_text
a year ago
660 B
10
Indexable
#include <iostream>
using namespace std;
int main() {
int x, y;
cin >> x;
cout << endl;
int a = x;
int t = 1;
while (a >= 10) {
a = a / 10;
t++;
}
int odd = 0;
int even = 0;
int b;
for (int i = 1; i <= t; i++) {
b = x % 10;
if (i % 2 == 0) {
even += b;
} else {
odd += b;
}
x = x / 10;
}
if (odd > even) {
cout << odd - even << endl;
} else if (odd < even) {
cout << even - odd << endl;
} else {
cout << 0 << endl;
}
return 0;
}
Editor is loading...
Leave a Comment