Advertisement
Guest User

Untitled

a guest
Jan 26th, 2016
199
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.65 KB | None | 0 0
  1. #include <conio.h>
  2. #include <iostream>
  3. #include <time.h>
  4.  
  5.  
  6. using namespace std;
  7.  
  8.  
  9. void main()
  10. {
  11.     srand(time(NULL));
  12.  
  13.     const int size = 20;
  14.     int arr[size] = {};
  15.     int in = 0, in2 = 0;
  16.     int max = arr[0], min = arr[0];
  17.  
  18.     for (int i = 0; i < size; i++)
  19.     {
  20.         arr[i] = -13 + rand() % 27;
  21.  
  22.         if (max < 0)
  23.         {
  24.             max = arr[i];
  25.             in = i;
  26.         }
  27.         if (min > arr[i])
  28.         {
  29.             min = arr[i];
  30.             in2 = i;
  31.         }
  32.  
  33.  
  34.     }
  35.     for (int i = 0; i < size; i++)
  36.     {
  37.         cout << "index" << "[" << i << "] " << arr[i] << "\n";
  38.  
  39.     }
  40.     cout << "Max " << max << " index " <<"[" <<in << "]" << endl;
  41.     cout << "Min " << min << " index " << "[" << in2 << "]";
  42.     _getch();
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement