/* To Interchange the Second Biggest and Second Smallest of ten numbers using conditional operator
	Step 1: To find smallest of ten numbers
	Step 2: To find smallest position of ten numbers
	Step 3: To find second smallest of ten numbers
	Step 4: To find Second Smallest position of ten numbers
*/
#include<stdio.h>
main()
{
	int i,sec_big,sec_big_pos,sec_sma,sec_sma_pos;
	int big,small,a[10];
	clrscr();
	for(i=0;i< 10;i++)
	{
		scanf("%d",&a[i]);
	}
	big=0;
	sec_big=0;
	small=a[0];
	sec_sma=a[0];

	for(i=0;i< 10;i++)       /*biggest part */
	{
		big=a[i]>big?a[i]:big;
	}
	for(i=0;i< 10;i++)       /* second biggest part*/
	{
		sec_big=(a[i]!=big && a[i]>sec_big)?a[i]:sec_big;
	}
	sec_big_pos=a[sec_big];

	for(i=0;i< 10;i++)       /* position finding for second biggest */
	{
		sec_big_pos=(a[i]!=big && a[i]>a[sec_big_pos])?i:sec_big_pos;
	}
	for(i=0;i<10;i++)       /* smallest part*/
	{
		small=a[i]< small?a[i]:small;
	}
	for(i=0;i<10;i++)       /* second smallest */
	{
		sec_sma=(a[i]!=small && a[i]< sec_sma)?a[i]:sec_sma;
	}
	sec_sma_pos=a[sec_sma];
	for(i=0;i<10;i++)      /* position finding for second smallest */
	{
		sec_sma_pos=(a[i]!=small && a[i]< a[sec_sma_pos])?i:sec_sma_pos;

	}
	printf("Biggest = %d\n",big);
	printf("Second Biggest = %d\n",sec_big);
	printf("Second Biggest Position = %d\n",sec_big_pos+1);
	printf("Smallest = %d\n",small);
	printf("Second Smallest = %d\n",sec_sma);
	printf("Second Smallest Position= %d\n",sec_sma_pos+1);

	printf("After interchanging the Array\n");
	for(i=0;i< 10;i++)
	printf("%d\t",a[i]);
	getch();
}
/* Exercise: 1. interchanging biggest and smallest number
		input : 2 3 4 5 6 79 8 9 12 76
		output: 2 76 4 5 6 79 8 9 12 3
*/