#include<stdio.h> int main( ) { int a[20],i,j,n,t,b; scanf("%d\n",&n); for(i=0;i<n;i++) { scanf("%d",&a[i]); } for(i=n-1;i>=0;i--) { for(j=0;j<i;j++) { if(a[j]>a[j+1]) { t=a[j]; a[j]=a[j+1]; a[j+1]=t; } } } for(i=0;i<n;i++) b=a[n-3]; printf("The third Largest element is %d",b); return 0; }
Problem Description
Given an array of distinct elements, find third largest element in it.Take the number of elements and the array as input.
Test Case 1
Input (stdin)
6 1 14 2 16 10 20
Expected Output
The third Largest element is 14
Test Case 2
Input (stdin)
7 19 -10 20 14 2 16 10
Expected Output
The third Largest element is 16
No comments:
Post a Comment