Professional Documents
Culture Documents
TCS Coding
TCS Coding
Coding Series
Online
Q1. Oxygen Value
Note:
1.The oxygen value entered should not be accepted if it is not in
the range between 1 and 100.
2.If the calculated maximum average oxygen value of the trainees
is below 70 then declare the trainees as unfit with a meaningful
message as “All trainees are unfit”
3.Average oxygen values should be rounded
Example 1:
Input #1:
95
92
95
92
90
92
90
92
Online
90
Output:
Trainee Number: 1
Trainee Number: 3
Round 1:
Oxygen value of trainee 1
Oxygen value of trainee 2
Oxygen value of trainee 3
Round 2:
Oxygen value of trainee 1
Oxygen value of trainee 2
Oxygen value of trainee 3
Round 3:
Oxygen value of trainee 1
Oxygen value of trainee 2
Oxygen value of trainee 3
Input #2:
91
Online
92
45
92
80
90
90
92
90
Solution:-
I. Python:-
T1 = int(0)
T2 = int(0)
T3 = int(0)
count = 1
while(count<=9):
x=int(input())
if(x>=1 and x<=100):
if(count%3==1):
T1=T1+x
elif(count%3==2):
T2=T2+x
else:
T3=T3+x
count=count+1
else:
Online
print("INVALID INPUT")
exit()
A1 = round(T1/3)
A2 = round(T2/3)
A3 = round(T3/3)
print(A1,A2,A3)
if(A1 <= 70 and A2 <= 70 and A3 <= 70):
print("All trainees are unfit")
exit()
if(A1 >= A2 and A1>= A3):
print("Trainee Number: 1")
if(A2 >= A1 and A2 >= A3):
print("Trainee Number: 2")
if(A3 >= A1 and A3 >= A2):
print("Trainee Number: 3")
II. In C++:-
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
int i, x, T1 = 0, T2 = 0, T3 = 0, count = 1;
double A1, A2, A3;
while(count <= 9)
Online
{
cin >> x;
if(x >= 1 && x <= 100)
{
if(count % 3 == 1)
{
T1 = T1 + x;
}
else if(count % 3 == 2)
{
T2 = T2 + x;
}
else
{
T3 = T3 + x;
}
count++;
}
else
{
cout << "INVALID INPUT";
count++;
return 0;
}
}
A1 = round(T1/3);
A2 = round(T2/3);
A3 = round(T3/3);
if(A1 <= 70 && A2 <= 70 && A3 <= 70)
Online
{
cout << "All trainees are unfit";
return 0;
}
if(A1 >= A2 && A1>= A3)
cout << "Trainee Number: 1"<< endl;
if(A2 >= A1 && A2 >= A3)
cout << "Trainee Number: 2"<< endl;
if(A3 >= A1 && A3 >= A2)
cout << "Trainee Number: 3" << endl;
return 0;
}