Advertisement
Guest User

zad2

a guest
Nov 20th, 2019
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.42 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. /*
  4. Podaj rekurencyjną funkcję SUMACYFR(n) znajdującą dla danej
  5. liczby naturalnej n sumę cyfr tej liczby.
  6. */
  7.  
  8. using namespace std;
  9.  
  10. int SUMACYFR(int n){
  11.         int suma=0;
  12.         while(n!=0){
  13.             suma+=n%10;
  14.             n=n%10;
  15.         }
  16.     return suma;
  17. }
  18.  
  19. int main(int argc, char** argv) {
  20.     int n,suma;
  21.     suma=0;
  22.    
  23.     cout<<"n: ";
  24.    
  25.     do{
  26.     cin>>n;
  27.     }while(n<0)
  28.    
  29.     cout<<"Wynik: "<<SUMACYFR(n);
  30.    
  31.     return 0;
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement