View Code of Problem 49

#include<stdio.h>

int main()
{
	int n;
	int a[n];
 	scanf("%d",&n);	
		for(int i=0;i<n;i++)
		{
			scanf("%d",&a[i]);
		}
		int max=0;
		int min=0;
		for(int i=0;i<n;i++)
		{
			if(a[i]>a[max]){max=i;}
			if(a[i]<a[min]){min=i;}
		}	
		int temp;
		temp=a[0];
		a[0]=a[min];
		a[min]=temp;
		temp=a[n-1];
		a[n-1]=a[max];
		a[max]=temp;
		for(int 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