Advertisement
PIBogdanov

C++

Jan 27th, 2023
38
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.54 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7.     int n;
  8.     cin >> n;
  9.  
  10.     int min = INT_MAX;
  11.     int max = INT_MIN;
  12.  
  13.     for (int i = 0; i < n; i++)
  14.     {
  15.         int num;
  16.         cin >> num;
  17.  
  18.         if (num > max)
  19.         {
  20.             int maxNum = num;
  21.  
  22.             max = maxNum;
  23.         }
  24.  
  25.         if (num < min)
  26.         {
  27.             int minNum = num;
  28.  
  29.             min = minNum;
  30.         }
  31.  
  32.     }
  33.  
  34.     cout << "Max number: " << max << "\n";
  35.  
  36.     cout << "Min number: " << min << "\n";
  37.  
  38.     return 0;
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement