Advertisement
Michal_Pilarski

zad24

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