c:求n得阶乘(递归的应用)
#include<stdio.h>
#include<stdlib.h>
int main(void){
int c;
c = factorial(5);
printf("the res is: %d\n",c);
system("pause");
//return 0;
}
int factorial(int a){
int res;
if(a<0){
printf("error\n");
system("pause");
exit(EXIT_FAILURE);
}
if(a==1||a==0)
res = 1;
if(a>1)
res = a*factorial(a-1);
return res;
}

浙公网安备 33010602011771号