1 #include<stdio.h>
2 //#include<stdlib.h>
3 int jiecheng(int i){
4 //①算n!
5 if(i==1)return 1;
6 return i*jiecheng(i-1);
7 }
8 int Fibonacci(int i){
9 //②算第i项斐波那契数列
10 if(i==1)return 1;
11 if(i==0)return 0;
12 return Fibonacci(i-1)+Fibonacci(i-2);
13 }
14 int power(int n,int k){
15 //③算n^k
16 if(k==1)return n;
17 return n*power(n,k-1);
18 }
19 int gcd(int m,int n){
20 //④用欧几里得算法算m与n的最大公约数
21 if(m%n==0)return n;
22 return gcd(n,m%n);
23
24 }
25 int DigitSum(int n){
26 //⑤输入一个非负整数,返回组成它的数字之和
27 if(n==0)return 0;
28 return (n%10)+DigitSum(n/10);
29 }
30 int DigitalRoot(int n){
31 //⑥整数n的数字根
32 if(n<10) return n;
33 return DigitalRoot(DigitSum(n));
34 }
35 int Comb(n,r){
36 //⑦计算组合数C(n,r);组合数C(n,r)=(P(n,r)/r!)=(n!/((n-r)!*r!));
37 // 存在如下公式:C(n,m)= C(n,n-m)= C(n-1,m-1)+C(n-1,m)
38 if(n==r||r==0)return 1;
39 return Comb(n-1,r-1)+Comb(n-1,r);
40 }
41
42 void main(){
43
44 printf("① %d
",jiecheng(5));
45 printf("② %d
",Fibonacci(6));
46 printf("③ %d
",power(2,3));
47 printf("④ %d
",gcd(18,24));
48 printf("⑤ %d
",DigitSum(12345));
49 printf("⑥ %d
",DigitalRoot(12345));
50 printf("⑦ %d
",Comb(6,4));
51
52 }
结果: