Type the Question

Saturday, February 16, 2019

Question Name:Third largest element

#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

Question Name:TOWER OF HANOI

#include < bits / stdc ++. h > #define lli long long using namespace std ; lli dp [ 202 ]; int main () { int t , n ; ...