View Code of Problem 49

#include<stdio.h>

int main()
{
	int n;
	int a[1000];
 	scanf("%d",&n);	
		for(int i=1;i<=n;i++)
		{
			scanf("%d",&a[i]);
		}
		int max=1;
		int min=1;
		for(int i=1;i<=n;i++)
		{
			if(a[i]>a[max])max=i;
			if(a[i]<a[min])min=i;
		}	
		int temp;
		temp=a[1];
		a[1]=a[min];
		a[min]=temp;
		temp=a[n];
		a[n]=a[max];
		a[max]=temp;
		for(int i=1;i<=n;i++)
		{
			printf("%d ",a[i]);
		}
		//printf("%d\n",a[n]);	
	return 0;
} 

Double click to view unformatted code.


Back to problem 49