一、运行结果;
二、源代码;
cs
# define _CRT_SECURE_NO_WARNINGS
# include <stdio.h>
//声明n的阶乘函数fac;
int fac(int n);
int main()
{
//初始化变量值;
int n, result;
//获取要阶乘的数;
printf("请输入要阶乘的n:");
scanf("%d", &n);
//调用阶乘fac函数;
result = fac(n);
//输出结果;
printf("结果为:%d\n", result);
return 0;
}
//实现fac函数;
int fac(int n)
{
//初始化变量值;
int c = 0;
//判断;
if ((n == 1) || (n == 0))
{
//赋值;
c = 1;
}
else
{
c = fac(n - 1) * n;
}
//返回值;
return c;
}