Physical Address
304 North Cardinal St.
Dorchester Center, MA 02124
Write a program that accepts sets of three numbers, and prints the second-maximum number among the three.
For each of the N triples, output one new line which contains the second-maximum integer among the three.
Input: 3
1 2 3
10 15 5
100 999 500
Output: 2
10
500
#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;
}
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)
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);
}
}
}
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
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 >>