Advertisement
MeehoweCK

Untitled

Nov 27th, 2018
180
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.39 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. /*
  6. A14.  Napisać funkcję
  7. int b(int n)
  8. która zwraca sumę cyfr liczby n w zapisie dziesiętnym. Można założyć, że parametr n
  9. jest dodatni.
  10. */
  11.  
  12. int b(int n)
  13. {
  14.     int suma = 0;
  15.     while(n > 0)
  16.     {
  17.         suma += n % 10;
  18.         n = n/10;
  19.     }
  20.     return suma;
  21. }
  22.  
  23. int main()
  24. {
  25.     cout << b(128648532);
  26.     return 0;
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement