Advertisement
rootuss

min max dziel

Feb 13th, 2017
447
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.99 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdlib>
  3. #include <ctime>
  4.  
  5. using namespace std;
  6.  
  7. void oblicz (int T[], int n)
  8. {
  9.     int dl, i=2, min, max;
  10.  
  11.     if (n%2) dl=n-2; else dl=n-1;
  12.     if (T[0]<=T[1])
  13.     {
  14.         min=T[0];
  15.         max=T[1];
  16.     }
  17.     else
  18.     {
  19.         min=T[1];
  20.         max=T[0];
  21.     }
  22.     while (i<dl)
  23.     {
  24.         if (T[i]<=T[i+1])
  25.         {
  26.             if(T[i]<min) min=T[i];
  27.             if(T[i+1]>max) max=T[i+1];
  28.         }
  29.         else
  30.         {
  31.             if(T[i+1]<min) min=T[i+1];
  32.             if(T[i]>max) max=T[i];
  33.         }
  34.  
  35.         i+=2;
  36.  
  37.     }
  38.     if(n%2)
  39.     {
  40.         if (T[n-1]<min) min=T[n-1];
  41.         else if (T[n-1]>max) max=T[n-1];
  42.     }
  43.     cout <<endl<<endl<< "Max wynosi: "<<max<<endl;
  44.     cout << "Min wynosi: "<< min<<endl;
  45. }
  46.  
  47. int main()
  48. {
  49.     srand(time(NULL));
  50.  
  51.     int min, max, T[9];
  52.  
  53.     for (int i=0; i<9; i++)
  54.     {
  55.         T[i]=rand()%11;
  56.         cout <<T[i]<<"  ";
  57.     }
  58.  
  59.     oblicz (T,9);
  60.  
  61.     return 0;
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement