VOOZH about

URL: https://www.geeksforgeeks.org/interview-experiences/tcs-coding-practice-question-average-of-2-numbers/

⇱ TCS Coding Practice Question | Average of 2 Numbers - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

TCS Coding Practice Question | Average of 2 Numbers

Last Updated : 11 Jul, 2025

Given two numbers, the task is to find the average of two numbers using Command Line Arguments. Examples:

Input: n1 = 10, n2 = 20
Output: 15

Input: n1 = 100, n2 = 200
Output: 150

Approach:

  • Since the numbers are entered as Command line Arguments, there is no need for a dedicated input line
  • Extract the input numbers from the command line argument
  • This extracted numbers will be in String type.
  • Convert these numbers into integer type and store it in variables, say num1 and num2
  • Find the average of the numbers using the formula ((num1 + num2)/2)
  • Print or return the average

Program: 

Output:

👁 Image
 
Comment