# Probability of getting more value in third dice throw in C++

Given three players A, B, C throwing dice, we have to find the probability of the C throwing the dice and the number scored by C is higher than both A and B.

To check the probability of getting more value, we have to keep in mind that the value of the third dice throw is higher than the previous two.

Like A thrown the dice and score 2 and B thrown the dice and scored 3 so the probability of C getting higher value is 3/6 = 1/2, because there are only 3 values which can be higher than the A and B, i.e 4, 5 and 6 so the probability will be 1/2 after reducing.

So, the result to be obtained by it should be further reduced.

Input

A = 3, B = 5

Output

1/6

Explanation − The only value which is greater than both 3 and 5 is 6 so, 1/6 is probability.

Input

A = 2, B = 4

Output

1/3

Explanation − The values which are higher than both 2 and 4 are 5 and 6 whose probability is 2/6 which can be reduced to 1/3.

## Approach used below is as follows to solve the problem

• We will find the maximum amongst the values of A and B

• Subtract the maximum of A and B from 6 and calculate its gcd with 6

• Return the results.

## Algorithm

Start
Step 1→ probability of getting more value in third dice
void probab_third(int a, int b)
declare int c = 6 - max(a, b)
declare int GCD = __gcd(c, 6)
Print GCD
Step 2→ In main()
Declare int a = 2, b = 2
Call probab_third(a, b)
Stop

## Example

Live Demo

#include <bits/stdc++.h>
using namespace std;
//probability of getting more value in third dice
void probab_third(int a, int b){
int c = 6 - max(a, b);
int GCD = __gcd(c, 6);
cout<<"probability of getting more value in third dice : " <<c / GCD << "/" << 6 / GCD;
}
int main(){
int a = 2, b = 2;
probab_third(a, b);
return 0;
}

## Output

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

probability of getting more value in third dice : 2/3

Updated on: 13-Aug-2020

51 Views