您的位置:首页 > 其它

c:求n得阶乘(递归的应用)

2012-07-29 15:15 162 查看
#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;
}


  
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: