c语言中定义函数和调用函数(在函数中调用其他函数,计算四个数中的最大值)
1、c语言在函数中调用其他函数(计算四个数中的最大值)
#include <stdio.h>
int max2(int a, int b)
{
return (a > b) ? a : b;
}
int max4(int x, int y, int z, int p)
{
return max2(max2(x, y), max2(z, p));
}
int main(void)
{
int n1, n2, n3, n4;
puts("please input four integers.");
printf("n1 = "); scanf("%d", &n1);
printf("n2 = "); scanf("%d", &n2);
printf("n3 = "); scanf("%d", &n3);
printf("n4 = "); scanf("%d", &n4);
printf("the max = %d\n", max4(n1, n2, n3, n4));
return 0;
}