View Code of Problem 49

#include<stdio.h>
int main()
{
	int n,i;
	int s[10];
	scanf("%d", &n); 
	for( i=0; i<n; i++ )
	{
		scanf("%d", &s[i]);
	}

	int t,p= s[0];
	int a,b;
	for( i=0; i<n; i++ )
	{
		if ( t>=s[i] )
		{
			t = s[i];
			a = i;
		}
	}
	s[a] = s[0];
	s[0] = t;
	for( i=0; i<n; i++ )
	{
		if ( p<=s[i] )
		{
			p = s[i];
			b = i;
		}
	}
	s[b] = s[n-1];
	s[n-1] = p;
	for ( i=0; i<n; i++ )
	{
		if ( i<n-1 )
		{
			printf("%d ", s[i]);
		}
		else
		{
			printf("%d", s[i]);
		}
	}
	return 0;
}

Double click to view unformatted code.


Back to problem 49