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; }

  

posted @ 2012-07-29 15:15  ligang305  阅读(149)  评论(0)    收藏  举报