For max and min NickDMax has given the perfect thing...
Now it's turn to find (n)th largest number [3rd largest or middle or whatever...]
I gave a thought to it and came up with this logic.
CODE
#include <stdio.h>
#define length 7
main()
{
int arr[length],i,j,max = -10000,oldmax = 0;
printf("Enter %d Numbers : ",length);
for(i = 0; i < length; i++)
{
printf("\nNumber %d :",i + 1);
scanf("%d",&arr[i]);
}
for(i = 0; i < length; i++)
{
if(arr[i] >= max) max = arr[i];
}
oldmax = max;
for(i = 0; i < 2; i++) //will give 3rd largest, set (length / 2) for middle number
{
//setting to arr[0] creates problem for desceding arrays
max = -10000;
for(j = 0;j < length;j++)
{
if(arr[j] < oldmax && arr[j] >= max)
max = arr[j];
}
oldmax = max;
}
printf("\n3rd Largest Number = %d",max);
}
now changing value in for loop from 2 to any other value gives say n
(n+1)th largest number. so (length/2) gives middle number.
Hope this will help you.