暨南大学2019年复试机试-01

热身题:递归求阶乘(不用递归不得分)

这道题没啥好讲的 ,属于热身送分题

#include<stdio.h>
//1<=n<=200
int f(int n){
	if(n==1){
		return 1;
	}
	else{
		return f(n-1)*n;
	} 
} 
int  main(){
	int n;
	printf("input n : ");
	while(scanf("%d",&n)!=EOF){		
		printf("the answer is %d\n",f(n));	
	}
}

猜你喜欢

转载自blog.csdn.net/qq_41935906/article/details/89023969