How to calculate strike rate of a batsman
Given two integers A and B representing the run scored and ball faced by a batsman in a Cricket match. The task is to calculate the Strike rate of the batsman.
Batting strike rate is a measure of how quickly a batsman achieves the primary goal of batting. It is mathematically equal to:
Strike Rate = (Runs Scored / Balls faced) * 100
Attention reader! Don’t stop learning now. Get hold of all the important mathematical concepts for competitive programming with the Essential Maths for CP Course at a student-friendly price. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.
Examples:
Input: A = 264, B = 173
Output: 152.601
Explanation:
Srike rate of batsman is equal to (264 / 173) * 100 = 162.601Input: A = 0, B = 10
Output: 0.00
Approach:
- Use the formula for the strike rate to calculate the strike rate.
Strike Rate = (Runs Scored / Balls faced) * 100 - Return the strike rate in float data type format.
Here is the implementation of the above approach:
C++
// C++ program to calculate strike// rate of a batsman#include <bits/stdc++.h>using namespace std;// function to calculate strike// rate of a batsmanfloat strikerate(int bowls, int runs){ float z; z = (float(runs) / bowls) * 100; return z;}// Driver Codeint main(){ int A, B; A = 264; B = 173; cout << strikerate(B, A) << endl; return 0;} |
Java
// Java program to calculate strike// rate of a batsmanclass GFG{ // function to calculate strike// rate of a batsmanstatic float strikerate(float bowls, float runs){ float z; z = (runs / bowls) * 100; return z;}// Driver Codepublic static void main(String[] args){ int A, B; A = 264; B = 173; System.out.println(strikerate(B, A));}}// This code is contributed by rock_cool |
Python3
# Python3 program to calculate strike# rate of a batsman# function to calculate strike# rate of a batsmandef strikerate(bowls, runs): z = (float(runs) / bowls) * 100; return z;# Driver CodeA = 264;B = 173;print(strikerate(B, A));# This code is contributed by Code_Mech |
C#
// C# program to calculate strike// rate of a batsmanusing System;class GFG{ // function to calculate strike// rate of a batsmanstatic float strikerate(float bowls, float runs){ float z; z = (runs / bowls) * 100; return z;}// Driver Codepublic static void Main(){ int A, B; A = 264; B = 173; Console.Write(strikerate(B, A));}}// This code is contributed by Code_Mech |
Javascript
<script>// Javascript program to calculate strike// rate of a batsman// function to calculate strike// rate of a batsmanfunction strikerate(bowls, runs){ let z; z = (runs / bowls) * 100; return z.toFixed(3);}// Driver code let A, B;A = 264;B = 173;document.write(strikerate(B, A));// This code is contributed by divyesh072019</script> |
152.601
Time Complexity: O (1)
Auxiliary Space: O (1)


