Advertisement
catalyn

recursivitate

Sep 18th, 2015
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.42 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int fact(int n)
  6. {
  7. int s=0;
  8. while(n)
  9. {s=s+n%10;
  10. n=n/10;}
  11. return s;
  12. }
  13.  
  14. int suma(int n)
  15. {
  16. if(n==0)
  17. return 0;
  18. else
  19. return suma(n/10)+n%10;
  20. }
  21.  
  22. int ogl(int n)
  23. {
  24. ok=0;
  25. while(n)
  26. {
  27. ok=ok*10+n%10;
  28. n=n/10;
  29.  
  30. }
  31. return ok;
  32. }
  33. int main()
  34. {
  35. cout<<suma(3434);
  36. return 0;
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement