View Code of Problem 49

#include <stdio.h>
int main( ){
	int t;
	int a[11];
	scanf("%d",&t);
	int i;
	for(i=0;i<t;i++){
		scanf("%d",&a[i]);
	}
	int min=0;
	int max=0;
	for(i=1;i<t;i++){
		if(a[i]<a[min])
		min=i;
		if(a[i]>a[max])
		max=i;
	}
	int temp;
	temp=a[0];
	a[0]=a[min];
	a[min]=temp;
	temp=a[t-1];
	a[t-1]=a[max];
	a[max]=temp;
	for(i=0;i<t;i++){
		printf("%d",a[i]);
		if(i!=t-1)
		printf(" ");
	}
	return 0;
}

Double click to view unformatted code.


Back to problem 49