View Code of Problem 49

#include<stdio.h>
#include<string.h>
int main()
{
	int n,i=0;
	scanf("%d",&n);
	int a[n-1];
	while(i<n)
	{
		int k;
		scanf("%d",&k);
		a[i]=k;
		i++;	
	}
	int max=0,min=0;
	for(int j=0;j<n;j++)
	{
		if(a[max]<a[j])max=j;
		if(a[min]>a[j])min=j;		
	}
	int t;
	t=a[0];
	a[0]=a[min];
	a[min]=t;
	t=a[n-1];
	a[n-1]=a[max];
	a[max]=t;
	for(int j=0;j<n;j++)printf("%d ",a[j]);
}
 

Double click to view unformatted code.


Back to problem 49