JosepRivaille

P26492: Nombres equilibrats

Mar 17th, 2015
452
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.20 KB | None | 0 0
  1. bool es_equilibrat(int n) {
  2.     int eq = 0, ps = 1;
  3.     while (n != 0) {
  4.         if (ps%2 != 0) eq = eq + n%10;
  5.         else eq = eq - n%10;
  6.         n = n/10;
  7.         ++ps;
  8.     }
  9.     if (eq == 0) return true;
  10.     else return false;
  11. }
Advertisement
Add Comment
Please, Sign In to add comment