Stolar228

Untitled

Sep 13th, 2022
1,014
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.61 KB | None | 0 0
  1.  
  2. #include <iostream>
  3. using namespace std;
  4.  
  5. #define size 10
  6.  
  7. int main() {
  8.  
  9.   double arr[size] = {-2, 4, -3, 5, 12, -23, -2, -234, 12, 234};
  10.  
  11.   double min = arr[0];
  12.   double max = arr[0];
  13.   int min_index = 0;
  14.   int max_index = 0;
  15.  
  16.   for (int i = 1; i < size; i++) {
  17.     if (arr[i] < min) {
  18.       min = arr[i];
  19.       min_index = i;
  20.     }
  21.  
  22.     if (arr[i] > max) {
  23.       max = arr[i];
  24.       max_index = i;
  25.     }
  26.  
  27.   }
  28.  
  29.   cout << "MAX: " << max << endl;
  30.   cout << "MAX INDEX: " << max_index << endl;
  31.  
  32.   cout << "MIN: " << min << endl;
  33.   cout << "MIN INDEX: " << min_index << endl;
  34.  
  35.   return 0;
  36. }
  37.  
Advertisement
Add Comment
Please, Sign In to add comment