Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstdlib>
- #include <ctime>
- using namespace std;
- void oblicz (int T[], int n)
- {
- int dl, i=2, min, max;
- if (n%2) dl=n-2; else dl=n-1;
- if (T[0]<=T[1])
- {
- min=T[0];
- max=T[1];
- }
- else
- {
- min=T[1];
- max=T[0];
- }
- while (i<dl)
- {
- if (T[i]<=T[i+1])
- {
- if(T[i]<min) min=T[i];
- if(T[i+1]>max) max=T[i+1];
- }
- else
- {
- if(T[i+1]<min) min=T[i+1];
- if(T[i]>max) max=T[i];
- }
- i+=2;
- }
- if(n%2)
- {
- if (T[n-1]<min) min=T[n-1];
- else if (T[n-1]>max) max=T[n-1];
- }
- cout <<endl<<endl<< "Max wynosi: "<<max<<endl;
- cout << "Min wynosi: "<< min<<endl;
- }
- int main()
- {
- srand(time(NULL));
- int min, max, T[9];
- for (int i=0; i<9; i++)
- {
- T[i]=rand()%11;
- cout <<T[i]<<" ";
- }
- oblicz (T,9);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement