最小和次小值,最大和次大值
int a[10]={0,1,6,9,67,45,62,23,7,10}; int j1=0,j2=1; if(a[j1]>a[j2]) { int temp=j1; j1=j2; j2=temp; } for(int i=2;i<10;i++) { if(a[j1]>a[i]) { j2=j1; j1=i; }else if(a[j2]>a[i]) { j2=i; } } cout<<a[j1]<<"\t"<<a[j2];
int a[10]={0,1,6,9,67,45,62,23,7,10}; int j1=0,j2=1; if(a[j1]>a[j2]) { int temp=j1; j1=j2; j2=temp; } for(int i=2;i<10;i++) { if(a[j1]>a[i]) { j2=j1; j1=i; }else if(a[j2]>a[i]) { j2=i; } } cout<<a[j1]<<"\t"<<a[j2];