View Code of Problem 49

#include<bits/stdc++.h>
using namespace std;
int main(){
	int t=0,i,n;
	int a[n];
	cin>>n;
	for(i=0;i<n;i++){
		cin>>a[i];
	}
	for(i=0;i<n;i++){
		if(a[i]<a[i+1]){
			t=a[0];
			a[0]=a[i];
			a[i]=t;
		}
		
	}
	for(i=0;i<n;i++){
		if(a[i]>a[i+1]){
		    t=a[n-1];
		    a[n-1]=a[i];
			a[i]=t;
		}

	}
	for(i=0;i<n-1;i++){
		cout<<a[i]<<" ";
	}
	cout<<a[n-1];
	return 0;
}

Double click to view unformatted code.


Back to problem 49