Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- using namespace std;
- int liczba, wynik = 0;
- int suma_cyfr(int wynik)
- {
- while (liczba > 0)
- {
- wynik += liczba%10;
- liczba /= 10;
- }
- return wynik;
- }
- int main()
- {
- cout << "Podaj liczbe: ";
- cin >> liczba;
- if(liczba<0)
- {
- cout<<"Podaj liczbe naturalna nastepnym razem :)"<<endl;
- return 0;
- }
- cout << "Suma cyfr podanej liczby wynosi: " << suma_cyfr(wynik) << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement