Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- //1
- int f(int n)
- {
- if(n <= 1) return 1;
- return f(n-1) * n;
- }
- //3
- int SC(int n)
- {
- if(n == 0) return 0;
- return SC(n / 10) + n % 10;
- }
- //4
- int NrC(int n)
- {
- if(n == 0) return 0;
- return NrC(n / 10) + 1;
- }
- //5
- int Sa(int n)
- {
- if(n < 1) return 0;
- return n * (n+1) + Sa(n-1);
- }
- double Sb(double n)
- {
- if(n < 1) return 0;
- return (1 / n) + Sb(n-1);
- }
- double Sc(double n)
- {
- if(n < 1) return 0;
- return n / ((n + 1)*(n + 2)) + Sc(n-1);
- }
- int main()
- {
- cout << f(4) << "\n\n";
- cout << SC(123) << "\n\n";
- cout << NrC(1234) << "\n\n";
- cout << Sa(3) << "\n\n";
- cout << Sb(3) << "\n\n";
- cout << Sc(3) << "\n\n";
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement