#include "stdafx.h"
#include <iostream>
using namespace std;
template <typename T>
T find_min_max(T* mas, size_t n);
int _tmain(int argc, _TCHAR* argv[])
{
double a[10] = { 0, 2, 4, 6, 7,
1, 2, 3, 8, 65.1 };
int a1[10] = { 0, 2, 4, 6, 7,
1, 2, 3, 8, 65.1 };
cout << find_min_max<double>(a, 10) << endl;
cout << find_min_max<int>(a1, 10) << endl;
return 0;
}
template <typename T>
T find_min_max(T* mas, size_t n)
{
T min = mas[0];
T max = mas[0];
for (size_t i = 1; i < n; i++)
{
if (max < mas[i]) max = mas[i];
if (min > mas[i]) min = mas[i];
}
return min - max;
}
Comments
0 B
|👍
/👎
0 B
|👍
/👎