Advertisement
andruhovski

prog0304-demo

Feb 23rd, 2016
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include "stdafx.h"
  2. #include <iostream>
  3. using namespace std;
  4. template <typename T>
  5. T find_min_max(T* mas, size_t n);
  6.  
  7. int _tmain(int argc, _TCHAR* argv[])
  8. {
  9.     double a[10] = { 0, 2, 4, 6, 7,
  10.         1, 2, 3, 8, 65.1 };
  11.     int a1[10] = { 0, 2, 4, 6, 7,
  12.         1, 2, 3, 8, 65.1 };
  13.     cout << find_min_max<double>(a, 10) << endl;
  14.     cout << find_min_max<int>(a1, 10) << endl;
  15.     return 0;
  16. }
  17.  
  18. template <typename T>
  19. T find_min_max(T* mas, size_t n)
  20. {
  21.     T min = mas[0];
  22.     T max = mas[0];
  23.     for (size_t i = 1; i < n; i++)
  24.     {
  25.         if (max < mas[i]) max = mas[i];
  26.         if (min > mas[i]) min = mas[i];
  27.     }
  28.     return min - max;
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement