Kacper_Michalak

Zadanie funkcje 13

Jan 30th, 2021
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.35 KB | None | 0 0
  1.  
  2. #include <iostream>
  3. using namespace std;
  4.  
  5. int SUMA_CYFR(int &x)
  6. {
  7.     int suma = 0;
  8.     int y=0;
  9.  
  10.     do
  11.     {
  12.         y = x % 10;
  13.         suma +=y;
  14.         x = x / 10;
  15.     } while (x > 0);
  16.     x = suma;
  17.     return x;
  18. }
  19.  
  20. int main()
  21. {
  22.     int x;
  23.     cout << "Podaj liczbe: " << endl;
  24.     cin >> x;
  25.  
  26.     do {
  27.         SUMA_CYFR(x);
  28.     } while (SUMA_CYFR(x) > 10);
  29.  
  30.     cout << SUMA_CYFR(x);
  31. }
  32.  
  33.  
Advertisement
Add Comment
Please, Sign In to add comment