Second Largest ||codechef||beginner solution ||programming info

Second Largest

Three numbers AB and C are the inputs. Write a program to find second largest among them.

Input

The first line contains an integer T, the total number of testcases. Then T lines follow, each line contains three integers AB and C.

Output

For each test case, display the second largest among AB and C, in a new line.

Constraints

  •  T  1000
  •  A,B,C  1000000

Example

Input
3 
120 11 400
10213 312 10
10 3 450

Output

120
312
10
SOLUTION USING C LANGUAGE:-
#include <stdio.h>
int main(void) {
    int T,A,B,C,i;
    scanf("%d\n",&T);
    for(i=0;i<T;i++)
    {
        scanf("%d\n%d\n%d\n",&A,&B,&C);
      if(A>B && A>C)
        {
            if(B>C)
            printf("%d\n",B);
            else
            printf("%d\n",C);
        }
          if(B>A && B>C)
        {
            if(A>C)
            printf("%d\n",A);
            else
            printf("%d\n",C);
        }
          if(C>B && C>A)
        {
            if(B>A)
            printf("%d\n",B);
            else
            printf("%d\n",A);
        }
    }
	// your code goes here
/*	if((A>B && A<C) || (A<B && A>C))
	printf("%d\n",A);
	else if((B>A && B<C) || (B<A && B>C))
	printf("%d\n",B);
	else
	printf("%d\n",C);
}*/
	return 0;
}
alternate solution:-
#include <stdio.h>
int main(void) {
    int T,A,B,C,i;
    scanf("%d\n",&T);
    for(i=0;i<T;i++)
    {
        scanf("%d\n%d\n%d\n",&A,&B,&C);
      /*  if(A>B && A>C)
        {
            if(B>C)
            printf("%d",B);
            else
            printf("%d",C);
        }
          if(B>A && B>C)
        {
            if(A>C)
            printf("%d",A);
            else
            printf("%d",C);
        }
          if(C>B && C>A)
        {
            if(B>A)
            printf("%d",B);
            else
            printf("%d",A);
        }
    }*/
	// your code goes here
	if((A>B && A<C) || (A<B && A>C))
	printf("%d\n",A);
	else if((B>A && B<C) || (B<A && B>C))
	printf("%d\n",B);
	else
	printf("%d\n",C);
}
	return 0;
}
Share:

No comments:

Post a Comment

Translate

Recommended platforms

  1. codechef
  2. hackerrank
  3. codeforces
  4. leetcode
  5. hackerearth

Popular Posts

programming_info. Powered by Blogger.

Blog Archive

Recent Posts

other platforms

  • geeks for geeks
  • w3schools
  • codepen
  • skillshare
  • udemy

Pages

reader support Support