标签:c语言 谭浩强 函数的嵌套调用 找4个整数中最大的数 递推
用函数的嵌套调用,找4个整数中最大的数。(递推)
解:程序:
#include<stdio.h>
int max2(int a,int b)
{
return (a > b ? a : b);
}
int max4(int a, int b,int c,int d)
{
int max2(int a, int b);
return max2(max2(max2(a,b),c),d);
}
int main()
{
int a, b, c,d,max;
printf("please enter four integer numbers:");
scanf("%d,%d,%d,%d", &a, &b,&c,&d);
max = max4(a, b,c,d);
printf("max is %d\n", max);
return 0;
}
结果:
please enter four integer numbers:-1,2,45,2
max is 45
请按任意键继续. . .
本文出自 “岩枭” 博客,请务必保留此出处http://yaoyaolx.blog.51cto.com/10732111/1746648
标签:c语言 谭浩强 函数的嵌套调用 找4个整数中最大的数 递推
原文地址:http://yaoyaolx.blog.51cto.com/10732111/1746648