Untitled

mail@pastecode.io avatar
unknown
plain_text
22 days ago
660 B
1
Indexable
Never
#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;
}
Leave a Comment