- 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 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

#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

- Related Questions & Answers
- Probability of getting at least K heads in N tosses of Coins in C++
- Probability of getting a sum on throwing 2 Dices N times in C++
- Dice Roll Simulation in C++
- Getting the highest value of a column in MongoDB?
- Getting the return value of Javascript code in Selenium.
- Subjective Probability Vs. Objective Probability
- Getting last value in MySQL group concat?
- Getting Minimum and Maximum Value in MySQL
- Python program to find probability of getting letter 'a' in some letters and k sized combinations
- Number of Dice Rolls With Target Sum in Python
- Find the number of players who roll the dice when the dice output sequence is given in C++
- Java program to merge two or more files alternatively into third file
- Program to find probability of getting assigned seat for the last person in an airplane after seat shuffling in Python
- Getting index of the specified value in a SortedList object in C#
- Swapping two variable value without using third variable in C/C++