1.#include
void main()
{
int max_4(int a,int b,int c,int d);
int a,b,c,d,max;
printf("Please enter 4 interder numbers:");
scanf("%d,%d,%d,%d",&a,&b,&c,&d);
max=max_4(a,b,c,d);
printf("max=%d\n",max);
}
int max_4(int a,int b,int c,int d)
{
int max_2(int x,int y); 注意:x,y均可以省略不写,或可以写成任意字符,对编译无影响!
int m;
m=max_2(a,b);
m=max_2(m,c);
m=max_2(m,d);
return(m);
}
int max_2(int a,int b)
{
return(a>b?a:b);
}
2.#include
int max_4(int a,int b,int c,int d); 注意:可以对调用函数提前声明,以后就不用声明了!
int max_2(int x,int y);
void main()
{int a,b,c,d,max;
printf("Please enter 4 interder numbers:");
scanf("%d,%d,%d,%d",&a,&b,&c,&d);
max=max_4(a,b,c,d);
printf("max=%d\n",max);
}
int max_4(int a,int b,int c,int d)
{
int max_2(int x,int y);
int m;
m=max_2(a,b);
m=max_2(m,c);
m=max_2(m,d);
return(m);
}
int max_2(int x,int y)
{
if(x>y)
return x;
else
return y;
}
3.#include
int max_4(int a,int b,int c,int d)
{
int max_2(int x,int y);
int m;
m=max_2(a,b);
m=max_2(m,c);
m=max_2(m,d);
return(m); 注意:可以先定义要调用的函数,以后就不必对调用函数声明了!
}
int max_2(int x,int y)
{
if(x>y)
return x;
else
return y;
}
void main()
{int a,b,c,d,max;
printf("Please enter 4 interder numbers:");
scanf("%d,%d,%d,%d",&a,&b,&c,&d);
max=max_4(a,b,c,d);
printf("max=%d\n",max);
}