csansoon

P3.14 X84338 Related sum of the halves of a number

Oct 24th, 2018
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.74 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main() {
  5.         int n, xf = 0, a  = 0, b = 0;
  6.         cin >> n;
  7.         for (int i = n; i != 0; i = i/10) ++xf;
  8.         if (xf%2 != 0 or n == 0) cout << "nothing" << endl;
  9.         else {
  10.                 xf = (xf/2);
  11.                 for (int at = xf; at != 0; --at) {
  12.                         a = a + n%10;
  13.                         n = n/10;
  14.                 }
  15.                 for (int bt = xf; bt != 0; --bt) {
  16.                         b = b + n%10;
  17.                         n = n/10;
  18.                 }
  19.                 if (a > b) cout << b << " < " << a << endl;
  20.                 else if (a < b) cout <<  b << " > " << a << endl;
  21.                 else cout << b << " = " << a << endl;
  22.         }
  23.  
  24. }
Advertisement
Add Comment
Please, Sign In to add comment