Advertisement
Guest User

Untitled

a guest
Jan 17th, 2020
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.42 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main()
  6.  
  7. {
  8.  
  9.    int n, a=0, b=0, va, m, ncif=1, i, z;
  10.  
  11.    cin >> n;
  12.  
  13.    m=n;
  14.  
  15.    while (m>9)
  16.  
  17.    {
  18.  
  19.        ++ncif; m/=10;
  20.  
  21.    }
  22.  
  23.    z=1;
  24.  
  25.    for (i=1; i<=ncif/2; ++i) z*=10;
  26.  
  27.    if (ncif%2==0) {  a=n/z; b=n%z; }
  28.  
  29.    else {  a=n/z; b=n%z; a=a/10; }
  30.  
  31.    va=a-b; if (va<0) va=-va;
  32.  
  33.    cout << va << "\n";
  34.  
  35.    return 0;
  36.  
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement