Advertisement
J00ker

(10-16)E

Oct 16th, 2014
36
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.76 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. //1
  6. int f(int n)
  7. {
  8. if(n <= 1) return 1;
  9. return f(n-1) * n;
  10. }
  11.  
  12. //3
  13. int SC(int n)
  14. {
  15. if(n == 0) return 0;
  16. return SC(n / 10) + n % 10;
  17. }
  18.  
  19. //4
  20. int NrC(int n)
  21. {
  22. if(n == 0) return 0;
  23. return NrC(n / 10) + 1;
  24. }
  25.  
  26. //5
  27. int Sa(int n)
  28. {
  29. if(n < 1) return 0;
  30. return n * (n+1) + Sa(n-1);
  31. }
  32.  
  33. double Sb(double n)
  34. {
  35. if(n < 1) return 0;
  36. return (1 / n) + Sb(n-1);
  37. }
  38.  
  39. double Sc(double n)
  40. {
  41. if(n < 1) return 0;
  42. return n / ((n + 1)*(n + 2)) + Sc(n-1);
  43. }
  44.  
  45. int main()
  46. {
  47. cout << f(4) << "\n\n";
  48. cout << SC(123) << "\n\n";
  49. cout << NrC(1234) << "\n\n";
  50. cout << Sa(3) << "\n\n";
  51. cout << Sb(3) << "\n\n";
  52. cout << Sc(3) << "\n\n";
  53. return 0;
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement