Advertisement
catalyn

probleme recursive 21.09.2015

Sep 21st, 2015
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.95 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4. int factorial (int n )
  5. {
  6. if(n==0)
  7. return 1;
  8. else
  9. return factorial(n-1)*n;
  10. }
  11. void factorial (int n ,int &f)
  12. {
  13. if(n==0)
  14. f=1;
  15. else
  16. {
  17.  
  18. factorial (n-1,f);
  19. f=f*n; }
  20. }
  21.  
  22. int cmmdc(int a ,int b)
  23. {
  24. if(b==0)
  25. return a;
  26. else
  27. return cmmdc(b,a%b);
  28.  
  29. }
  30.  
  31. int sumcif(int x)
  32. {
  33. if(x==0)
  34. return 0;
  35. else
  36. return x%10+sumcif(x/10);
  37. }
  38. void sumcif(int n,int &s)
  39. {
  40. if(n==0)
  41. s=0;
  42. else
  43. {
  44.  
  45. sumcif(n/10,s);
  46. s=s+n%10;
  47. }
  48. }
  49.  
  50. int nr_cif_zero(int x)
  51.  
  52. {
  53. if(x>9)
  54. {
  55. if(x%10==0)
  56. return 1+nr_cif_zero(x/10);
  57. else
  58. return nr_cif_zero(x/10);
  59. }
  60. else
  61. if(x!=0)
  62. return 0;
  63. else
  64. return 1;
  65.  
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement