#用递归法求n!(函数定义)
#include<>
int sum(int a)
{
long b;
if(a==1||a==0)
b=1;
else
b=sum(a-1)*a;
return(b);
}
int main()
{
long i;
int n;
printf("请输入n的值:");
scanf("%d",&n);
i=sum(n);
printf("5!=%d\n",i);
}
运行结果:n=5
输出:5!=120
#用递归法求n!(函数定义)
#include<>
int sum(int a)
{
long b;
if(a==1||a==0)
b=1;
else
b=sum(a-1)*a;
return(b);
}
int main()
{
long i;
int n;
printf("请输入n的值:");
scanf("%d",&n);
i=sum(n);
printf("5!=%d\n",i);
}
运行结果:n=5
输出:5!=120