QUESTION
Given an array of distinct elements, find Third largest element in it.\n\nTake the number of elements and the array as input.
“TESTCASE_1”: “5\n-1 -2 -3 -4 1\n###—###SEPERATOR—###—\nThe third Largest element is -2”, “TESTCASE_2”: “7\n19 -10 20 14 2 16 10\n###—###SEPERATOR—###—\nThe third Largest element is 16”, “TESTCASE_3”: “8\n20 11 25 17 3 19 -1 -7\n###—###SEPERATOR—###—\nThe third Largest element is 19”, “TESTCASE_4”: “0\n###—###SEPERATOR—###—\n0”, “TESTCASE_5”: “0\n###—###SEPERATOR—###—\n0
ANSWER
#include <stdio.h>
int main()
{
int n;
scanf("%d",&n);
int arr[n];
int i,j;
for(i=0;i<n;i++)
scanf("%d",&arr[i]);
for(i=0;i<n;i++)
{
for(j=i+1;j<n;j++)
{
if(arr[i]>arr[j])
{
int temp=arr[i];
arr[i]=arr[j];
arr[j]=temp;
}
}
}
//float sum=arr[n-1]+arr[n-2];
printf("The third Largest element is %d",arr[n-3]);
return 0;
}