龙空技术网

C语言每日一练17——递归方法求阶乘n

折腾的小大叔 41

前言:

今天兄弟们对“用递归法求n的阶乘的程序流程图”大概比较关怀,你们都需要分析一些“用递归法求n的阶乘的程序流程图”的相关内容。那么小编同时在网摘上网罗了一些有关“用递归法求n的阶乘的程序流程图””的相关资讯,希望同学们能喜欢,各位老铁们快快来学习一下吧!

题目

利用递归方法求n的阶乘n!。

思路递归思想0的阶乘是1,容易忽视实现代码

/* ======================== Name        : 20200618.c Author      : 折腾的小大叔 Version     : Copyright   : Your copyright notice Description : Hello World in C, Ansi-style ======================== */#include <stdio.h>#include <stdlib.h>#define MAXINT 4294967295int Recursion(int num){	int result = 1;	if(num == 0)	{		result = 1;	}	else	{		for(int loop = 1;loop <= num;loop++)		{			result *= loop;		}	}	return (result > MAXINT) ? 0 : result;}int main(void){	int input;	int result;	printf("请输入你想计算那个整数的阶乘\n");	scanf("%d",&input);	result = Recursion(input);	if(result == 0)	{		printf("WARNNING:超过MAXINT\n");	}	else	{		printf("结果是:%d\n",result);	}	return 0;}
运行过程推荐阅读

C语言每日一练16——指针的指针使用

C语言每日一练15——小屁孩赛跑

C语言每日一练14——读写文本

C语言每日一练13——指针数组构建字符串数组

标签: #用递归法求n的阶乘的程序流程图 #用递归法求n的阶乘的程序流程图怎么画 #用递归的方法求n的阶乘 #请编程求出n阶乘n由键盘输入 #c语言从1的阶乘加到n的阶乘