195k views
5 votes
Write a python program to comput
nCr= n!/(n-r)!r! Giving the value of n and r as input

1 Answer

3 votes

Answer:

```python

import math

# Get the values of n and r from the user

n = int(input("Enter the value of n: "))

r = int(input("Enter the value of r: "))

# Calculate nCr using the formula n! / (n-r)! * r!

nCr = math.factorial(n) / (math.factorial(n - r) * math.factorial(r))

# Print the result

print("The value of nCr is:", nCr)

```

In this program, we first import the `math` module to access the `factorial` function, which calculates the factorial of a number.

Then, we prompt the user to enter the values of `n` and `r` using the `input` function. We convert the user inputs to integers using the `int` function.

Next, we calculate `nCr` using the provided formula `n! / (n-r)! * r!`. We use the `factorial` function from the `math` module to calculate the factorials.

Finally, we print the calculated value of `nCr` using the `print` function.

By running this program and providing the values of `n` and `r` as input, it will compute and display the value of `nCr`.

User Pratap Singh
by
8.5k points