求大佬解答
定义函数fun(),求输入的4个整数中的最大值(用函数的嵌套调用实现)
回复 楼主 小白羊2022
没整明白 嵌套是啥意思,递归吗???
程序代码:
#include <stdio.h>
int fun(int idx)
{
static int max=0;
int tmp=0;
if (idx>4) return max;
printf("请输入整数:");
scanf("%d",&tmp);
if(tmp>max) max=tmp;
fun(++idx);
}
int main()
{
int max=fun(1);
printf("最大值是%8d\n",max);
return 0;
}
/*
输出示例:
PS D:\wp> ./ct2
请输入整数:58
请输入整数:45
请输入整数:369
请输入整数:2
最大值是 369
PS D:\wp>
*/








