|ZZ| c++ 第一次作业..
May 16, 2007 12:12
这道题是上机作业...第一堂课就布置的...当时做的有个错误但是老师帮忙改了..没想到昨晚再写..就发现自己还犯当时的那个错误..真是够傻的..不举一反三也就算了..做过的竟然还.....
再谢谢..帮忙帮我改的人.....此题依然仅供参考.....若发现错误..请帮忙指出...在此感谢..
//编写一个重载函数max,分别求两个整数或3个整数的最大值。
//形参个数不同。
#include<iostream.h>
int max(int x,int y) //函数1.
{
if(x>y) return x;
else return y;
}
int max(int x,int y,int z) //函数2.
{
if(x>y&&x>z) return x;
else if(x>y&&x<=z) return z;
else if(x<=y&&y>z) return y;
else return z;
}
void main()
{
int x,y,z,t1,t2;
cout<<"input x,y,z"<<endl;
cin>>x>>y>>z;
t1=max(x,y); //调用函数1.
cout<<"t1="<<t1<<endl;
t2=max(x,y,z); //调用函数2.
cout<<"t2="<<t2<<endl;
}
//形参个数不同。
#include<iostream.h>
int max(int x,int y) //函数1.
{
if(x>y) return x;
else return y;
}
int max(int x,int y,int z) //函数2.
{
if(x>y&&x>z) return x;
else if(x>y&&x<=z) return z;
else if(x<=y&&y>z) return y;
else return z;
}
void main()
{
int x,y,z,t1,t2;
cout<<"input x,y,z"<<endl;
cin>>x>>y>>z;
t1=max(x,y); //调用函数1.
cout<<"t1="<<t1<<endl;
t2=max(x,y,z); //调用函数2.
cout<<"t2="<<t2<<endl;
}
|ZZ| 珍珠字..
|ZZ|胡思乱想...