View Code of Problem 49

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

Double click to view unformatted code.


Back to problem 49