定义一个用于计算阶乘的函数jiecheng,该函数参数为整型变量n,返回值为n的阶乘n!;注:函数jiecheng中需

2024-12-28 21:49:38
推荐回答(1个)
回答1:


    

以下是代码:

#include "stdio.h"
int jiecheng(int x)
{
if(x<0)
return 0;
if(0==x||1==x)
return 1;
return jiecheng(x-1)*x;

}
int main()
{
int m,n,t;
printf("输入m的值:",m);
scanf("%d",&m);
t=jiecheng(m);
if(0==t)
printf("%d的值输入有误!\n",m);
else
printf("%d! = %d\n",m,t);

printf("输入n的值:",n);
scanf("%d",&n);
t=jiecheng(n);
if(0==t)
printf("%d的值输入有误!\n",n);
else
printf("%d! = %d\n",n,t);
return 0;
}