#include <stdio.h> #include <stdlib.h> /* run this program using the console pauser or add your own getch, system("pause") or input loop */ int swap(int *p,int *q) { int t; t=*p; *p=*q; *q=t; } int main(int argc, char *argv[]) { int T,i,t,m,n,b,c; int a[100]; scanf("%d",&T); for(i=0;i<T;i++) { scanf("%d",&a[i]); } for(i=0,m=0,n=a[0];i<T;i++)//max { if(n<a[i]) { n=a[i]; m=i; } } for(i=0,b=0,c=a[0];i<T;i++)//min { if(c>a[i]) { c=a[i]; b=i; } } swap(&a[b],&a[0]); swap(&a[m],&a[T-1]); for(i=0;i<T;i++) { printf("%d ",a[i]); } } |
Double click to view unformatted code.