Advertisement
WiktorMalisak

Zadanie 24

Mar 30th, 2020
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.51 KB | None | 0 0
  1. #include<iostream>
  2. using namespace std;
  3.  
  4.     int SUMA_CYFR(int liczba)
  5.     {
  6.         if(liczba==0)
  7.         {
  8.             return 0;
  9.         }
  10.             return (liczba%10)+SUMA_CYFR(liczba/10);
  11.     }
  12.  
  13. int main() {
  14.     int liczba;
  15.     cout << "Podaj liczbe: ";
  16.     cin >> liczba;
  17.     do
  18.     {
  19.         liczba = SUMA_CYFR(liczba);
  20.         cout << "Test: " << liczba << endl;
  21.     } while ((liczba/10) % 10 != 0);
  22.  
  23.     cout << "Suma cyfr tej liczby wynosi: ";
  24.     cout << liczba << endl;
  25.     return 0;
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement