Liverpool will play against a certain team n number of times in a tournament. A match can end with 3 possible results: win, loss or tie, and each outcome is equally likely. Write a C program to calculate the probability that there will be exactly k number of wins for Liverpool. Note: After submission in HackerRank, you have to upload the program (c file) on eduserver. Program filename must be RollNo_2.c (without any blank space). Input Format The inputs to the program are two positive integers: n and k (separated by a space) Constraints k<=n Output Format The output of the program is a float value representing the probability Sample Input 0 2 1 Sample Output 0 0.444444 Explanation 0 Here, n=2 and k=1. So, all possible outcomes: WW, WL, LW, LL, WT, TW, TT, LT, TL (W indicates win, L indicates loss, and T indicates tie). In this case, the number of outcomes having exactly 1 win: 4. Hence, the probability is 4/9=0.444444 which is the output.
Liverpool will play against a certain team n number of times in a tournament. A match can end with 3 possible results: win, loss or tie, and each outcome is equally likely. Write a C program to calculate the probability that there will be exactly k number of wins for Liverpool.
Note: After submission in HackerRank, you have to upload the program (c file) on eduserver. Program filename must be RollNo_2.c (without any blank space).
Input Format
The inputs to the program are two positive integers: n and k (separated by a space)
Constraints
k<=n
Output Format
The output of the program is a float value representing the probability
Sample Input 0
Sample Output 0
Explanation 0
Here, n=2 and k=1. So, all possible outcomes: WW, WL, LW, LL, WT, TW, TT, LT, TL (W indicates win, L indicates loss, and T indicates tie). In this case, the number of outcomes having exactly 1 win: 4. Hence, the probability is 4/9=0.444444 which is the output.
Step by step
Solved in 4 steps with 2 images