#include<iostream> using namespace std; int main() { int n,max=0,min=0; cin>>n; int a[n];//先输入n再定义数组!!! for(int i=0;i<n;i++) cin>>a[i]; for(int j=0;j<n;j++) { if(a[j]<a[min]) min=j; if(a[j]>a[max]) max=j; } int temp; temp=a[0]; a[0]=a[min]; a[min]=temp; temp=a[n-1]; a[n-1]=a[max]; a[max]=temp; for(int k=0;k<n;k++) cout<<a[k]<<" "; } |
Double click to view unformatted code.