SHARE
TWEET

Minimum i maksimum metodą optymalną

Kasamundo Oct 16th, 2019 87 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top