View Code of Problem 49

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

Double click to view unformatted code.


Back to problem 49