C++编程题求助!急!

来源:百度知道 编辑:UC知道 时间:2024/06/25 05:44:30
有2个题目
1。用函数摸板实现找出两个数值中最小值的程序。
2。用函数摸板实现找出3个数值中按最小值到最大值排列的程序。
谢谢

都调试通过了

第一题:
#include "iostream"

using namespace std;

template<class T>
T getmin(T&x,T&y)
{
return x<y?x:y;
}

int _tmain(int argc, _TCHAR* argv[])
{
float x,y;
cout<<"请输入两个数:";
cin>>x>>y;
cout<<x<<"和"<<y<<"中较小的一个数是:"<<getmin(x,y)<<endl;
return 0;
}

第二题:
#include "iostream"

using namespace std;

template<class T>
void numsort(T&x,T&y,T&z)
{
T temp;
if(x>y)
{
temp=x;x=y;y=temp;
}
if(x>z)
{
temp=x;x=z;z=temp;
}
if(y>z)
{
temp=y;y=z;z=temp;
}
}

int _tmain(int argc, _TCHAR* argv[])
{
int x,y,z;
cout<<"请输入三个数:";
cin>>x>>y>>z;
numsort(x,y,z);
cout&