Second Largest
Three numbers A, B 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 A, B and C.
Output
For each test case, display the second largest among A, B and C, in a new line.
Constraints
- 1 ≤ T ≤ 1000
- 1 ≤ 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; }
No comments:
Post a Comment