- C++ Basics
- C++ Home
- C++ Overview
- C++ Environment Setup
- C++ Basic Syntax
- C++ Comments
- C++ Data Types
- C++ Variable Types
- C++ Variable Scope
- C++ Constants/Literals
- C++ Modifier Types
- C++ Storage Classes
- C++ Operators
- C++ Loop Types
- C++ Decision Making
- C++ Functions
- C++ Numbers
- C++ Arrays
- C++ Strings
- C++ Pointers
- C++ References
- C++ Date & Time
- C++ Basic Input/Output
- C++ Data Structures

- C++ Object Oriented
- C++ Classes & Objects
- C++ Inheritance
- C++ Overloading
- C++ Polymorphism
- C++ Abstraction
- C++ Encapsulation
- C++ Interfaces

# 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 Articles
- Find probability that a player wins when probabilities of hitting the target are given in C++
- If the probability of winning a game is $0.995$, then find the probability of losing.
- If the probability of winning a game is $0.999$, then find the probability of losing.
- If the probability of winning a game is $0.990$, then find the probability of losing.
- If the probability of winning a game is \( 0.3 \), what is the probability of loosing it?
- How Can Companies Target the Different Family Life Cycles of an Individual?
- How to measure the Binary Cross Entropy between the target and the input probabilities in PyTorch?
- Write a function that generates one of 3 numbers according to given probabilities in C++
- Count elements in a vector that match a target value or condition in C++
- C++ program to find the probability of a state at a given time in a Markov chain
- Match, the terms of column A correctly with the phrases given in column B.
- Match the reactions given in Column (A) with the names given in column (B).
- Fill in the blanks: Sum of the probabilities of each outcome in an experiment is ...........
- Match the names of the Scientists given in column A with their contributions towards the understanding of the atomic structure as given in column B
- Match the items given in Column I with the items of Column II.