#include
using namespace std;
int main()
{
int a[5],i,max,min;
for(i=0;i<=4;i++)
{
cin>>a[i];
}
for (i=0;i<=4;i++)
{
if(a[i]>a[i++])
{max=a[i];min=a[i++];}
else {max=a[i++];min=a[i++];}
}
cout<<"最大值為"<<max<<"最小值"<<min<<endl;
return 0;
}
看循環中如果i=4的話,你的i一直在++,越界了,明白不?
for (i=0;i<4;i++)
{
if(a[i]>a[i+1])
{max=a[i];min=a[i+1];}
else {max=a[i+1];min=a[i+1];}
}