View Code of Problem 49

#include <stdio.h>
int main()
{
	int n,i;
	int a[10] = { 0 };
	scanf("%d", &n);
	for (i = 0; i < n; i++)
		scanf("%d", &a[i]);
	int min=a[0], max=a[0];
	int d=0, b=0;
	for (i = 0; i < n; i++)
	{
		if (a[i] < min)
		{
			min = a[i];
			d = i;
		}
		if (a[i] > max)
		{
			max = a[i];
			b = i;
		}
	}
	int temp=a[d];
	a[d] = a[0];
	a[0] = temp;
	temp = a[b];
	a[b] = a[n-1];
	a[n-1] = temp;
	for (i = 0; i < n; i++)
	{
		printf("%d", a[i]);
		if (i == n - 1)
			printf("\n");
		else
			printf(" ");
	}
	return 0;
}

Double click to view unformatted code.


Back to problem 49