Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- unsigned const n = 8;
- void input(int array[]) {
- int t;
- for (int i = 0; i < n; ++i) {
- cout << "Podaj " << i + 1 << " element: ";
- cin >> t;
- array[i] = t;
- }
- }
- void output(int array[]) {
- cout << "[";
- for (int i = 0; i + 1 < n; ++i)
- cout << array[i] << ", ";
- cout << array[n - 1] << "]" << endl;
- }
- int mini(int array[]) {
- int m = array[0];
- for (int i = 0; i < n / 2; ++i)
- if (array[i] < m) m = array[i];
- return m;
- }
- int maxi(int array[]) {
- int m = array[0];
- for (int i = 0; i < n / 2; ++i)
- if (array[i] > m) m = array[i];
- return m;
- }
- void conquer(int array[]) {
- int low[n /2], high[n / 2];
- for (int i = 0; i < n / 2; i++) {
- if (array[i * 2] < array[i * 2 + 1]) {
- low[i] = array[i * 2];
- high[i] = array[i * 2 + 1];
- }
- else {
- high[i] = array[i * 2];
- low[i] = array[i * 2 + 1];
- }
- }
- cout << "mini: " << mini(low) << endl;
- cout << "maxi: " << maxi(high) << endl;
- }
- int main() {
- int tablica[n];
- input(tablica);
- output(tablica);
- conquer(tablica);
- return 0;
- }
Add Comment
Please, Sign In to add comment