304 North Cardinal St.
Dorchester Center, MA 02124

# Second Max of Three Numbers CodeChef Solution

## Problem – Second Max of Three Numbers CodeChef Solution

#### Problem Statement

Write a program that accepts sets of three numbers, and prints the second-maximum number among the three.

#### Input

• First line contains the number of triples, N.
• The next N lines which follow each have three space separated integers.

#### Output

For each of the N triples, output one new line which contains the second-maximum integer among the three.

#### Constraints

• 1 ≤ N ≤ 6
• 1 ≤ every integer ≤ 10000
• The three integers in a single triplet are all distinct. That is, no two of them are equal.

#### Sample 1:

``````Input: 3
1 2 3
10 15 5
100 999 500
Output: 2
10
500
``````

### Second Max of Three Numbers CodeChef Solution in C++17

``````#include <iostream>
using namespace std;

void solve(){
int a,b,c;
cin>>a>>b>>c;
if(a>b && a<c){
cout<<a<<"\n";
}else if(a>c && a<b){
cout<<a<<"\n";
}else if(b>a && b<c){
cout<<b<<"\n";
}else if(b>c && b<a){
cout<<b<<"\n";
}else if(c>a && c<b){
cout<<c<<"\n";
}else if(c>b && c<a){
cout<<c<<"\n";
}
}

int main ()
{
int t;
cin>>t;
while(t--){
solve();
}
return 0;
}``````

### Second Max of Three Numbers CodeChef Solution in Python3

``````n=int(input())
for i in range(n):
x,y,z=map(int,input().split())
a=max(x,y,z)
b=min(x,y,z)
if x<a and x>b:
print(x)
elif y<a and y>b:
print(y)
elif z<a and z>b:
print(z)``````

### Second Max of Three Numbers CodeChef Solution in Java

``````import java.util.*;
import java.lang.*;
import java.io.*;

class Codechef
{
public static void main (String[] args) throws java.lang.Exception
{
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();

for (int i = 1; i <= t; i++) {
int a =sc.nextInt();
int b = sc.nextInt();
int c = sc.nextInt();

if((a > b && a < c) || (a > c && a < b))
System.out.println(a);
else if ((b > a && b < c) || (b >c && b < a))
System.out.println(b);
else System.out.println(c);
}
}
}
``````
##### Second Max of Three Numbers CodeChef Solution Review:

In our experience, we suggest you solve this Second Max of Three Numbers CodeChef Solution and gain some new skills from Professionals completely free and we assure you will be worth it.

If you are stuck anywhere between any coding problem, just visit Queslers to get the Second Max of Three Numbers CodeChef Solution

Find on CodeChef

##### Conclusion:

I hope this Second Max of Three Numbers CodeChef Solution would be useful for you to learn something new from this problem. If it helped you then don’t forget to bookmark our site for more Coding Solutions.

This Problem is intended for audiences of all experiences who are interested in learning about Data Science in a business context; there are no prerequisites.

Keep Learning!

More Coding Solutions >>

LeetCode Solutions

Hacker Rank Solutions

CodeChef Solutions