Advertisement
GarikK

Homework(minMaxDiapazon)

Feb 24th, 2020
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.83 KB | None | 0 0
  1. // Arrays.cpp : This file contains the 'main' function. Program execution begins and ends there.
  2. //
  3.  
  4. #include "pch.h"
  5. #include <iostream>
  6. using namespace std;
  7.  
  8. int main()
  9. {
  10.     int months[12];
  11.     int dEnd, dBegin;
  12.     for (int i = 0; i < 12; i++)
  13.     {
  14.         cout << "Please enter your income " << i + 1 << endl;
  15.         cin >> months[i];
  16.     }
  17.     cout << "Vvedite nachalo v diapazone" << endl;
  18.     cin >> dBegin;
  19.     cout << "Vvedite konec v diapazone" << endl;
  20.     cin >> dEnd;
  21.     int max = 0, min = 1000000;
  22.     int min_month, max_month;
  23.     for (int c = dBegin; c < dEnd; c++)
  24.     {
  25.         if (max < months[c])
  26.         {
  27.             max = months[c];
  28.             max_month = c + 1;
  29.         }
  30.         if (months[c] < min)
  31.         {
  32.             min = months[c];
  33.             min_month = c + 1;
  34.         }
  35.     }
  36.     cout << "MIN - " << min << " Mesajc " << min_month << endl;
  37.     cout << "MAX - " << max << " Mesajc " << max_month;
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement