Documente Academic
Documente Profesional
Documente Cultură
1) Factorial
1. int fact(int n)
2. {
3. if(n == 0 ) return 1;
4. else return n*fact(n-1);
5. }
2) 𝑆1 = 2 + 4 + ⋯ + 2𝑛
1. int S1(int n)
2. {
3. if(n == 0 ) return 0;
4. else return 2*n+S1(n-1);
5. }
3) 𝑆2 = 21 + 22 + ⋯ + 220
1 1 1
4) 𝑃1 = ∗ ∗ …∗
1+2 1+4 1+2𝑛
1. int P1(int n)
2. {
3. if(n==0) return 1;
4. else return 1.0/(1+2*n)*P1(n-1);
5. }
5) 𝑃2 = 2 ∗ 22 ∗ … ∗ 220
1. int fib(int n)
2. {
3. if(n==0 || n==1) return 1;
4. else return fib(n-1)+fib(n-2);
5. }
1. int S(int n)
2. {
3. if(n==0) return 0;
4. else return n%10+S(n/10);
5. }
8) Oglinditul lui 𝑛 ∈ ℕ∗