//递归求阶乘,我们宁愿做普通程序员
//递归调用的代码初始#include<stdio.h>
void recursion(void)
{
static int count =10;
printf("Hi!\n");
if (--count)
{
recursion();
}
}
int main(void)
{
recursion();
return 0;
}
//递归求阶乘,我们宁愿做普通程序员
#include<stdio.h>
long fact(int num)
{
long result;
for (result = 1; num>1;num--)
{
result *= num;
}
return result;
}
int main(void)
{
intnum;
printf("请输入一正整数:");
scanf_s("%d", &num);
printf("%d的阶乘是%d", num,fact(num));
return 0;
}
#include<stdio.h>
long fact(int num);
long fact(int num)
{
long result;
if (num > 0)
result = num * fact(num - 1);
else
{
result = 1;
}
return result;
}
int main(void)
{
intnum;
printf("请输入一正整数:");
scanf_s("%d", &num);
printf("%d的阶乘是%d", num, fact(num));
return 0;
页:
[1]