Given three integers runs, matches, and notout representing the number of runs scored, number of innings played by the batsman and number of times he remained Not Out respectively, the task is to calculate the Batting Average of the batsman.
Note: If the batsman was never dismissed, print “NA” as the no average can be defined.
Input: runs = 10000, matches = 250, notout = 50
Number of times batsman was dismissed = 250 – 50 = 200
Batting Average = 10000 / 200 = 50.
Input: runs = 100, matches = 1, notout = 1
Follow the steps below to solve the problem:
- Calculate the number of dismissals, equal to matches – notout.
- Calculate the Batting Average, equal to runs/ (matches – notout).
Below is the implementation of the above approach:
Time Complexity: O(1)
Auxiliary Space: O(1)
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- How to calculate strike rate of a batsman
- Find the subarray with least average
- Find the average of first N natural numbers
- Program to find simple moving average
- Find array elements that are greater than average
- Find average of two numbers using bit operation
- Find the average of k digits from the beginning and l digits from the end of the given number
- Find the ratio of number of elements in two Arrays from their individual and combined average
- Find the deleted value from the array when average of original elements is given
- Find temperature of missing days using given sum and average
- Average of a stream of numbers
- Sum of average of all subsets
- Compute average of two numbers without overflow
- Average numbers in array
- Average of odd numbers till a given odd number
- Average of even numbers till a given even number
- Average of first n odd naturals numbers
- Average of first n even natural numbers
- Average of Squares of Natural Numbers
- Longest subarray having average greater than or equal to x
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.