1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
| # include <stdio.h> int main (void) { int a[5],max,min,i,x,y,t; printf("input 5 numbers:"); for (i=0;i<5;i++) { scanf("%d",&a[i]); } printf("start:"); for (i=0;i<5;i++) { printf("%4d",a[i]); } printf("\n"); max = a[0]; min = a[0]; x = y = 1; for (i=1;i<5;i++) { if (a[i]>max) { max = a[i]; x = i+1; } if (a[i]<min) { min = a[i]; y = i+1; } } t = a[x-1]; a[x-1] = a[y-1]; a[y-1] = t; printf("max is the %d number,max=%d\n",x,max); printf("min is the %d number,min=%d\n",y,min); printf("after exchange:"); for (i=0;i<5;i++) { printf("%4d",a[i]); } printf("\n"); return 0; }
|