View Code of Problem 49

#include<bits/stdc++.h>
using namespace std;

int main()
{
	int n,max=0,min=0;
	scanf("%d",&n);
	int a[20];
	for(int i=0;i<n;i++)
	{
		scanf("%d",&a[i]);
		if(a[i]>a[max])
		{
			max=i;
		}
		else if(a[i]<a[min])
		{
			min=i;
		}
	}
	int temp;
	swap(a[0],a[min]);
	swap(a[max],a[n-1]);
	for(int i=0;i<n;i++)
	{
		if(i!=0) printf(" ");
		printf("%d",a[i]);
	}
	
	
}

Double click to view unformatted code.


Back to problem 49