这是一个很简单的C语言程序,重要的是考验思考问题的角度:
方法1:
#include
void main()
{
int a,b,c;
scanf("%d%d%d",&a,&b,&c);
if(a>=b && a>=c)
printf("max=%d\n",a);
else if(b>=a && b>=c)
printf("max=%d\n",b);
else printf("max=%d\n",c);
}
方法2:
#include
double max3(double x,double y,double z)
{
return (x>y?x:(y>z?y:z));
}
void main()
{
double a,b,c,max;
scanf("%lf%lf%lf",&a,&b,&c);
max=max3(a,b,c);
printf("%lf\n",max);
}
方法3:
#include
double max3(double x,double y,double z)
{
return (x>y?x:y)>z?(x>y?x:y):z;
}
void main()
{
double a,b,c,max;
scanf("%lf%lf%lf",&a,&b,&c);
max=max3(a,b,c);
printf("%lf\n",max);
}
方法4:
#include
double max3(double x,double y,double z)
{
double t;
t=x;
if(y>t)
t=y;
if(z>t)
t=z;
return t;
}
void main()
{
double a,b,c,max;
scanf("%lf%lf%lf",&a,&b,&c);
max=max3(a,b,c);
printf("%lf\n",max);
}
方法5:可以利用此法进行输出数据排序,从小到大分别为x,y,z
#include
double max3(double x,double y,doublez)
{
double t;
if(x>y)
{
t=x;
x=y;
y=t;
}
if(x>z)
{
t=x;
x=z;
z=t;
}
if(y>z)
{
t=y;
y=z;
z=t;
}
return z;
}
void main()
{
double a,b,c,max;
scanf("%lf%lf%lf",&a,&b,&c);
max=max3(a,b,c);
printf("%lf\n",max);
}
方法6
#include
int main()
{
int x,y,z;
cin>>x>>y>>z;
if(x>y)
if(x>z)
cout<<"max="<
cout<<"max="<
if(z
cout<<"max="<
}