Advertisement
Kasamundo

Minimum i maksimum metodą optymalną

Oct 16th, 2019
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.56 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdlib>
  3. #include<ctime>
  4.  
  5. using namespace std;
  6.  
  7. int main()
  8. {
  9.     srand(time(NULL));
  10.     int tab[10],min_,max_;
  11.     for (int i=0;i<10;i++)
  12.     {
  13.         tab[i]=rand()%50+1;
  14.         cout << tab[i] << endl;
  15.     }
  16.      min_=tab[0];
  17.      max_=tab[0];
  18.      for (int i=0;i<10;i++)
  19.     {
  20.      if(min_>=tab[i])
  21.     {
  22.         min_=tab[i];
  23.     }
  24.     else if(max_<tab[i])
  25.     {
  26.         max_=tab[i];
  27.     }
  28.     }
  29.  
  30.     cout << "minimum wynosi: " << min_ <<endl;
  31.     cout << "maksimum wynosi: " << max_;
  32.  
  33.  
  34.     return 0;
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement