给定两个整数A和B,表示板球比赛中击球手的得分和击球动作。任务是计算击球手的打击率。
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
例子:
Input: A = 264, B = 173
Output: 152.601
Explanation:
Srike rate of batsman is equal to (264 / 173) * 100 = 162.601
Input: A = 0, B = 10
Output: 0.00
方法:
- 使用执行价格的公式来计算执行价格。
打击率=(得分/得分)* 100 - 以浮点数据类型格式返回行使价。
这是上述方法的实现:
C++
// C++ program to calculate strike
// rate of a batsman
#include
using namespace std;
// function to calculate strike
// rate of a batsman
float strikerate(int bowls, int runs)
{
float z;
z = (float(runs) / bowls) * 100;
return z;
}
// Driver Code
int main()
{
int A, B;
A = 264;
B = 173;
cout << strikerate(B, A)
<< endl;
return 0;
}
Java
// Java program to calculate strike
// rate of a batsman
class GFG{
// function to calculate strike
// rate of a batsman
static float strikerate(float bowls, float runs)
{
float z;
z = (runs / bowls) * 100;
return z;
}
// Driver Code
public 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 batsman
def strikerate(bowls, runs):
z = (float(runs) / bowls) * 100;
return z;
# Driver Code
A = 264;
B = 173;
print(strikerate(B, A));
# This code is contributed by Code_Mech
C#
// C# program to calculate strike
// rate of a batsman
using System;
class GFG{
// function to calculate strike
// rate of a batsman
static float strikerate(float bowls,
float runs)
{
float z;
z = (runs / bowls) * 100;
return z;
}
// Driver Code
public static void Main()
{
int A, B;
A = 264;
B = 173;
Console.Write(strikerate(B, A));
}
}
// This code is contributed by Code_Mech
Javascript
输出:
152.601
时间复杂度: O(1)
辅助空间: O(1)