c语言 编程实现求n!要求用定义求阶乘的函数

2024-11-29 20:55:31
推荐回答(1个)
回答(1):

#include
long fac(unsigned n)
{
if (n == 0 || n == 1)
{
return 1;
}
else
{
return (n * fac(n - 1));
}
}
int main()
{
unsigned ui;
printf("输入计算的阶乘:");
scanf("%u", &ui);
printf("%u的阶乘为:%u\n", ui, fac(ui));
return 0;

}