View Code of Problem 49

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

int main() {
	int n,i;
	int a[1000];
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d",&a[i]);
	}
	int min=0,max=0;
	for(i=0;i<n;i++){
		if(a[i]<a[min]){
			min=i;
		}
		if(a[i]>a[max]){
			max=i;
		}
	}
	int temp;
	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-1;i++){
		printf("%d ",a[i]);
	}
	printf("%d",a[i]);
}

Double click to view unformatted code.


Back to problem 49