C语言用递归求1到5的阶乘
作者:互联网
#include<stdio.h>
int main()
{
int fact(int j);
int i;
for(i = 0;i < 6;i++)
{
printf("%d! = %d\n",i,fact(i));
}
}
int fact(int j)
{
int sum;
if(j == 0)
{
sum = 1;
}
else
{
sum = j * fact(j - 1);
}
return sum;
}
结果如下
标签:return,递归,int,sum,C语言,阶乘,main,fact 来源: https://blog.csdn.net/AKE_XBZ/article/details/122759398