码迷,mamicode.com
首页 > 编程语言 > 详细

C语言小练习

时间:2019-01-25 23:51:06      阅读:252      评论:0      收藏:0      [点我收藏+]

标签:oid   result   语言   递归   error   阶乘   tmp   bsp   printf   

//递归求数的阶乘
#include <stdio.h>
long recursion(int n);
void main()
{
	int n;
	long result;
	scanf("%d",&n);

	result=recursion(n);
	printf("%d!=%ld\n",n,result);

}
long recursion(int n)
{
	long tmp_result;
	if(n==0 || n==1)
	{
		tmp_result=n;
	}else if(n<0){
		printf("error input");
	}
	else
	{
	tmp_result=recursion(n-1)*n;
	}
	return tmp_result;
}

 

C语言小练习

标签:oid   result   语言   递归   error   阶乘   tmp   bsp   printf   

原文地址:https://www.cnblogs.com/yanweichen/p/10322275.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!