用递归求阶乘:
#include<stdio.h>
int factorial(n);
int main()
{
int n;
scanf("%d",&n);
printf("thefactorial of n is %d.\n",factorial(n));
return0;
}
int factorial(int n)
{
if(n>1)
returnn*factorial(n-1);
else
return1;
}
用递归求阶乘:
#include<stdio.h>
int factorial(n);
int main()
{
int n;
scanf("%d",&n);
printf("thefactorial of n is %d.\n",factorial(n));
return0;
}
int factorial(int n)
{
if(n>1)
returnn*factorial(n-1);
else
return1;
}