C语言实现求阶乘和阶乘的和:
#include<stdio.h>
int getMul(int n){ //递归调用计算阶乘!n
int mul=1;
if(n==1){
mul==1;
return mul;
}else{
mul=n*getMul(n-1);
return mul;
}
}
int getSum(int n){ //求阶乘的和
int sum=1;
if(n==0){
sum=0;
}else{
sum = getMul(n)+getSum(n-1);
}
return sum;
}
int main(){
int n,h,s;
printf("please input n:");
scanf("%d",&n);
printf("!n=%d\n",getMul(n));
printf(" s=%d\n",getSum(n));
}