View Code of Problem 3895

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

Double click to view unformatted code.


Back to problem 3895