View Code of Problem 49

#include <stdio.h>
int main(){
	int n;
	scanf("%d",&n);
	int num[n];
	for(int i=0; i<n; i++)
		scanf("%d",&num[i]);
	int min=num[0],max=num[n-1];
	int k,l,temp1,temp2;
	for(int j=0; j<n; j++)
		{
			if(num[j]<min)
			{
				min=num[j];
				k=j;
			}
			if(num[j]>max)
			{
				max=num[j];
				l=j;
			}
		}
	temp1=num[0];
	num[0]=num[k];
	num[0]=temp1;
	temp2=num[n-1];
	num[n-1]=num[l];
	num[l]=temp2;
	return 0;
}

Double click to view unformatted code.


Back to problem 49