View Code of Problem 49

#include <stdio.h>

int main()
{
	int n,i;
	while(scanf("%d",&n)!=EOF)
	{
		int a[20],maxi=0,mini=0,temp;
		for(i=0;i<n;i++)
		{
			scanf("%d",&a[i]);
			if(a[maxi]<a[i])
				maxi=i;
			if(a[mini]>a[i])
				mini=i;
		}
		temp=a[maxi];
		a[maxi]=a[n-1];
		a[n-1]=temp;
		temp=a[mini];
		a[mini]=a[0];
		a[0]=temp;
		for(i=0;i<n-1;i++)
			printf("%d ",a[i]);
		printf("%d\n",a[n-1]);
	}
	return 0;
}

Double click to view unformatted code.


Back to problem 49