PiotrJurek

Zad24

Mar 30th, 2020
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.40 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int SUMA_CYFR(int n)
  6. {
  7. int x=0;
  8. for(n; n>0; n=n/10)
  9. {
  10. x=x+(n%10);
  11. }
  12. return x;
  13. }
  14.  
  15. int main()
  16. {
  17. cout << SUMA_CYFR(456) << endl;
  18. cout << SUMA_CYFR(1578) << endl;
  19. cout << SUMA_CYFR(34) << endl;
  20.  
  21. int a;
  22. cin >> a;
  23. while(a>9)
  24. {
  25. a=SUMA_CYFR(a);
  26. }
  27. cout << a;
  28. return 0;
  29. }
Add Comment
Please, Sign In to add comment