C++ prime plus 第八章8.8-5

来源:互联网 发布:约瑟夫环用到的算法 编辑:程序博客网 时间:2024/04/27 15:35
#include <iostream>
using namespace std;
template <typename T>
void max5(T a[5]);
int main()
{
    int a[5]={100,20,-9,58,16};
    double g[5]={-1.589456,-2.45646740,-9.4654,-58.456465,-160.123};
    max5(a);
    max5(g);
    return 0;
}
template <typename T>
void max5(T a[5])
{
    T temp=a[1];
     int n=sizeof(a);
     for(int i=0;i<n;++i)
     {
         if(temp<a[i])
             temp=a[i];
     }
     cout<<"The max num of the array  is "<< temp<<endl;
 }
                                             
0 0