Advertisement
VEGASo

Lab #5 Ex. 4

Nov 5th, 2022
864
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.33 KB | None | 0 0
  1. #include <iostream>
  2. #include <limits>
  3.  
  4. using namespace std;
  5.  
  6.  
  7. template <typename T>
  8.  
  9. void closureMin(int def = 3)
  10. {
  11.     cout << "\nЗамыкание в " << typeid(T).name() << "\n";
  12.  
  13.     cout << "\nНа минимальном значении: \n";
  14.     for (int i = def; i >= -def; i--) // на минимальном
  15.     {
  16.         if (i >= 0)
  17.             cout << static_cast<int>(numeric_limits<T>::min()) << "+" << i << " = " << static_cast<int>(numeric_limits<T>::min() + i) << endl;
  18.         else if (i < 0)
  19.             cout << static_cast<int>(numeric_limits<T>::min()) << i << " = " << static_cast<int>(numeric_limits<T>::min() - i) << endl;
  20.     }
  21.  
  22.     cout << "\nНа максимальном значении: \n";
  23.     for (int i = def; i >= -def; i--) // на максимальном
  24.     {
  25.         if (i >= 0)
  26.             cout << static_cast<int>(numeric_limits<T>::max()) << "+" << i << " = " << static_cast<int>(numeric_limits<T>::max() + i) << endl;
  27.         else if (i < 0)
  28.             cout << static_cast<int>(numeric_limits<T>::max()) << i << " = " << static_cast<int>(numeric_limits<T>::max() - i) << endl;
  29.     }
  30. }
  31.  
  32.  
  33. int main()
  34. {
  35.     setlocale(LC_ALL, "RU");
  36.  
  37.     closureMin<int>();
  38.     closureMin<unsigned int>();
  39.     closureMin<long>();
  40.     closureMin<unsigned long>();
  41.     closureMin<long long>();
  42.     closureMin<unsigned long long>();
  43.     closureMin<char>();
  44.     closureMin<unsigned char>();
  45.  
  46.  
  47.     return 0;
  48. }
  49.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement