View Code of Problem 49

#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
int a[20];
int main(){
	int x,min1,max1,y;
	int q,w;
	scanf("%d",&x);
	memset(a,0,sizeof(a));
	min1=999999999;
	max1=-999999999;
	for(int i=0;i<x;i++){
		scanf("%d",&a[i]);
		if(a[i]<min1){
			min1=a[i];
			q=i;
		}
		if(a[i]>max1){
			max1=a[i];
			w=i;
		}
	}
	y=a[0];
	a[0]=a[q];
	a[q]=y;
	y=a[x-1];
	a[x-1]=a[w];
	a[w]=y;
	for(int i=0;i<x;i++){
		printf("%d",a[i]);
		if(i!=x-1){
			printf(" ");
		}
		else{
			printf("\n");
		}
	}
	return 0;
}

Double click to view unformatted code.


Back to problem 49