This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.
#include<iostream>
#include"limits.h"
usingnamespacestd;
intmain(){
intd[]={9,6,7,5,13,6,2};
intn=8;
intmax=INT_MIN;
intmin=INT_MAX;
boolflag=false;
if(n%2){
n--;
flag=true;
}
for(inti=0;i<n-1;i+=2){
if(d[i]<=d[i+1]){
if(d[i]<min)
min=d[i];
if(d[i+1]>max)
max=d[i+1];
}
else{
if(d[i]>max)
max=d[i];
if(d[i+1]<min)
min=d[i+1];
}
}
//若数组长度为奇数,还需要和最后一个数作比较
if(flag){
if(d[n]<min)
min=d[n];
if(d[n]>max)
max=d[n];
}
cout<<"The max value of the array is: "<<max<<endl;
cout<<"The min value of the array is: "<<min<<endl;