Advertisement
JosepRivaille

Problem X98097: Posicions senars i parelles relacionades

Mar 14th, 2015
400
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.66 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4.  
  5. //Pre: Un natural n
  6. //Post: Suma xifres parells, senars i la relació
  7. int main() {
  8.     int n, p = 0, s = 0;
  9.     cin >> n;
  10.     while (n != 0) {
  11.         s = s + n%10;
  12.         n = n/10;
  13.         p = p + n%10;
  14.         n = n/10;
  15.     }
  16.     cout << s << ' ' << p << endl;
  17.     if (p >= s and s != 0) {
  18.         if (p%s != 0) cout << "res" << endl;
  19.         else cout << p << " = " << p/s << " * " << s << endl;
  20.     }else if (s >= p and p != 0) {
  21.         if (s%p != 0) cout << "res" << endl;
  22.         else cout << s << " = " << s/p << " * " << p << endl;
  23.     }else if (s == 0 or p == 0) {
  24.         if (s == 0) cout << "0 = 0 * " << p << endl;
  25.         else if (p == 0) cout << "0 = 0 * " << s << endl;
  26.     }
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement