- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

# Probability of A winning the match when individual probabilities of hitting the target given in C++

Given with two players let’s say A and B both are trying to get a penalty for winning the match. Given with four integer variables a, b, c, d so the probability of A getting the penalty first is a / b and probability of B getting the penalty first is c / d.

The one who scores the penalty first will win the match and as per the given problem statement program must find the probability of A winning the match.

**Input**

a = 10, b = 20, c = 30, d = 40

**Output**

probability is 0.5333

**Input**

a = 1, b = 2, c = 10, d = 11

**Output**

probability is 0.523

## Approach used in the below program is as follows

Input the values of four integer variables a, b, c, d

Subtract the probability of B winning the match from the total probability and we will get the resultant probability of A winning the match

e * (1 / (1 - (1 - f) * (1 - f))))

Where, e is the probability of A winning the match and f is the probability of B winning the match

Display the probability of A winning the match

## Algorithm

Start Step 1→ Declare function to calculate the probability of winning double probab_win(int a, int b, int c, int d) Declare double e = (double)a / (double)b Declare double f = (double)c / (double)d return (e * (1 / (1 - (1 - f) * (1 - f)))) Step 2→ In main() Declare variable as int a = 10, b = 20, c = 30, d = 40 Call probab_win(a, b, c, d) Stop

## Example

#include <bits/stdc++.h> using namespace std; // calculate the probability of winning the match double probab_win(int a, int b, int c, int d){ double e = (double)a / (double)b; double f = (double)c / (double)d; return (e * (1 / (1 - (1 - f) * (1 - f)))); } int main(){ int a = 10, b = 20, c = 30, d = 40; cout<<"probability is "<<probab_win(a, b, c, d); return 0; }

## Output

If run the above code it will generate the following output −

probability is 0.5333

- Related Questions & Answers
- Find probability that a player wins when probabilities of hitting the target are given in C++
- How to measure the Binary Cross Entropy between the target and the input probabilities in PyTorch?
- C++ program to find the probability of a state at a given time in a Markov chain
- PyTorch – How to invert the colors of an image randomly with a given probability?
- Find the probability of a state at a given time in a Markov chain - Set 1 in Python
- Write a function that generates one of 3 numbers according to given probabilities in C++
- How to get the value of the target attribute of a link in JavaScript?
- How to search the value of the target attribute of a link in JavaScript?
- Adjusting the heights of individual subplots in Matplotlib in Python
- How to change the target of a link in HTML?
- How to match one of the two given expressions using Java RegEx?
- Probability of a random pair being the maximum weighted pair in C++
- Match any single character in the given set.
- Which event occurs in JavaScript when the dragged element is over the target?
- How to find the name and the target of a form in JavaScript?