Stolar228

Untitled

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