Last Updated: 25 Nov, 2020

Average Marks

Easy
Asked in companies
HikeIBMHyland

Problem statement

You are given the name of a student in the form of a character ‘firstLetterOfName’ and 3 integers ‘M1’, ‘M2’, ‘M3’ representing the marks of the student in 3 subjects. You have to print the ‘firstLetterOfName’ of the student and the average marks obtained by the student.

Note: You need to print the integer part of the average only and neglect the decimal part.

For Example :
If ‘firstLetterOfName’ = ‘K’, ‘M1’ = 10, ‘M2’ = 6 and ‘M3’ = 9, then the average marks would be around 7.67. Hence, the output should be as follows:
K 7
Input Format :
The first line contains a single integer T representing the number of test cases.

The first line of each test case contains a character ‘firstLetterOfName’ denoting the first character of the name of the student.

The second line of each test case contains 3 space-separated integers ‘M1’, ‘M2’, and ‘M3’ representing marks of the student in 3 subjects.
Output Format :
For each test case, print two space-separated values i.e. first character of the name of the student and the average marks of the student.

Output for every test case will be printed in a separate line.
Constraints:
1 <= T <= 10
‘A’ <= ‘firstLetterOfName’ <= ‘Z’
0 <= M1 <= 100
0 <= M2 <= 100
0 <= M3 <= 100

Time Limit: 1 sec

Approaches

01 Approach

The idea is to simply find out the sum of marks in the 3 subjects and then divide it by the total number of subjects to find the average marks. 

 

Here is the algorithm:

  1. Initialize integer variable ‘TOTAL’ = ‘M1’ + ‘M2’ + ‘M3’.
  2. Initialize integer variable ‘AVERAGE’ = ‘TOTAL’ / 3. (Note that the value of average is automatically rounded off to its floor when stored in an integer variable).
  3. Print ‘firstLetterOfName’ and ‘AVERAGE’ separated by space.