用函数模板比较两个数的大小

#include<iostream>
using namespace std;

//用模板实现输出两个数当中最小的值
template<class T>
T tmin( T x, T y)
{
return x<y?x:y;
}

void main()
{
int a = 5,b = 10;
float c = 3.1415 , d = 6.5536;
char e = 'a', f = 'c';
cout << "a,b 当中最小的数是:" << tmin(a,b) << endl;
cout << "c,d 当中最小的数是:" << tmin(c,d) << endl;
cout << "e,f 当中最小的数是:" << tmin(e,f) << endl;
}

 

posted on 2022-10-26 20:27  进取  阅读(98)  评论(0编辑  收藏  举报