Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int suma_cyfr(int n) {
- int suma = 0;
- if (n == 0) {
- return 0;
- }
- while (n > 0) {
- suma += n % 10;
- n /= 10;
- }
- return suma;
- }
- bool liczba_jest_jednocyfrowa(int n) {
- return n < 10;
- }
- int main() {
- int n, suma;
- do {
- cout << "Podaj nieujemną liczbę całkowitą: ";
- cin >> n;
- if (n < 0) {
- cout << "Liczba musi być nieujemna!" << endl;
- continue;
- }
- do {
- suma = suma_cyfr(n);
- n = suma;
- cout << "Wynik to: " << suma << endl;
- } while (!liczba_jest_jednocyfrowa(n));
- } while (n < 0);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment