View Code of Problem 49

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

 }
	

Double click to view unformatted code.


Back to problem 49