#include<iostream> using namespace std; void getMaxMin(int a[], int len) { int max, min; if (len % 2) { max = min = a[0]; for (int i = 1; i < len; i += 2) { if (a[i] < a[i + 1]) { if (a[i + 1]>max) { max = a[i + 1]; } if (a[i] < min) { min = a[i]; } } else { if (a[i]>max) { max = a[i]; } if (a[i + 1] < min) { min = a[i + 1]; } } } } else { if (a[0]>a[1]) { max = a[0]; min = a[1]; } else { max = a[1]; min = a[0]; } for (int i = 2; i < len; i += 2) { if (a[i] < a[i + 1]) { if (a[i + 1]>max) { max = a[i + 1]; } if (a[i] < min) { min = a[i]; } } else { if (a[i]>max) { max = a[i]; } if (a[i + 1] < min) { min = a[i + 1]; } } } } cout << "max: " << max << endl; cout << "min: " << min << endl; } int main() { int a[] = {1,4,5,2,8,9,2,0,11,22,345,1,3}; int N = sizeof a / sizeof a[0]; getMaxMin(a, N); }