View Code of Problem 49

#include<bits/stdc++.h>
using namespace std;
int a[10];
int main(){
	int min=0,max=0;
	int n,tmp,ans;
	cin>>n;
	for(int i=0;i<n;i++)
		cin>>a[i];
	for(int i=0;i<n;i++)
		{
			if(a[i]>a[max])max=i;
		}
	for(int i=0;i<n;i++){
		if(a[i]<a[min])min=i;
	}
		
	
	
	
	swap(a[0],a[min]);
	swap(a[n-1],a[max]);
	for(int i=0;i<n;i++)cout<<a[i]<<" ";
	return 0;
}

Double click to view unformatted code.


Back to problem 49