10
Jul.2008
输入三个数(int,float型),求其最大值。
#include
using namespace std;
template
T max(T a,T b,T c) //定义一个函数模板,使函数可以适应下面输入数据的类型的不同
{ T tmp;
tmp=(a>b)?a:b; //判断最大数
tmp=(tmp>c)?tmp:c;
return tmp; //返回得到的最大数 }
int main()
{ cout<<"pls choose the type of the data;1;int,2:float"<
int type;
cin>>type;
switch(type) //根据选择的数据类型
{ case 1:
{ int x,y,z,result; //上面的函数模板根据这里定义的数据类型,来确定具体执行时参数的类型
cout<<"pls input the x ,y ,z!"<
cin>>x>>y>>z;
result=max(x,y,z);
cout<
case 2:
{ float x,y,z,result;
cout<<"pls input the x ,y ,z!"<
cin>>x>>y>>z;
result=max(x,y,z);
cout<
default:cout<<"pls input the right letter! 1 or 2 !~"<
}
return 0;
}
#include
using namespace std;
template
T max(T a,T b,T c) //定义一个函数模板,使函数可以适应下面输入数据的类型的不同
{ T tmp;
tmp=(a>b)?a:b; //判断最大数
tmp=(tmp>c)?tmp:c;
return tmp; //返回得到的最大数 }
int main()
{ cout<<"pls choose the type of the data;1;int,2:float"<
int type;
cin>>type;
switch(type) //根据选择的数据类型
{ case 1:
{ int x,y,z,result; //上面的函数模板根据这里定义的数据类型,来确定具体执行时参数的类型
cout<<"pls input the x ,y ,z!"<
cin>>x>>y>>z;
result=max(x,y,z);
cout<
case 2:
{ float x,y,z,result;
cout<<"pls input the x ,y ,z!"<
cin>>x>>y>>z;
result=max(x,y,z);
cout<
default:cout<<"pls input the right letter! 1 or 2 !~"<
}
return 0;
}
作者:菜鸟学编程@Bo-Blog
地址:http://www.node-net.org/read.php?17
版权所有©转载时必须以链接形式注明作者和原始出处及本声明!
为
2009/05/05 23:26
菜鸟学编程 回复于 2009/05/17 23:42
这个回复见解明了,呵呵。谢了~
分页: 1/1
1
1














输入一个不多于五位的正整
C++实现凯撒密码加密


