#include <stdio.h> #include <stdlib.h> #include <string.h> #include <math.h> /* run this program using the console pauser or add your own getch, system("pause") or input loop */ int main() { int n,i,temp; int a[1000]; scanf("%d",&n); for(i=0;i<n;i++){ scanf("%d",&a[i]); } int max=0; for(i=0;i<n;i++){ if(a[max]<a[i]){ max=i; } } temp=a[max]; a[max]=a[n-1]; a[n-1]=temp; int min=0; for(i=0;i<n;i++){ if(a[min]>a[i]){ min=i; } } temp=a[min]; a[min]=a[0]; a[0]=temp; for(i=0;i<n-1;i++){ printf("%d ",a[i]); } printf("%d",a[i]); } |
Double click to view unformatted code.