View Code of Problem 49

#include<stdio.h>
void swap(int A[],int k,int m){
	int temp=A[k];
	A[k]=A[m];
	A[m]=temp;
}
int main(){
	int n,i,k=0;
	scanf("%d",&n);
     int A[n];
	for(i=0;i<n;i++){
		scanf("%d",&A[i]);
		if(A[i]>A[k]){
			k=i;	
		}
	}
   swap(A,k,n-1);
	k=0;
	for(i=0;i<n;i++){
		if(A[i]<A[k]){
			k=i;
		}
	}
	swap(A,k,0);
	for(i=0;i<n;i++){
		printf("%d ",A[i]);
	} 
	return 0;
} 

Double click to view unformatted code.


Back to problem 49