Write a Python program using functions to find the value of nPr and nCr without using inbuilt factorial() function.

'''  In NCR and NPR, C stands for Combinations, and P stands for permutations. Now for combinations, it is the number of ways you can pick r objects out of n. In permutations, it is the number of ways you can pick r objects out of n and then arrange them.  '''

n=int(input('Enter value of n : ')) ''' Accept values from user '''

r=int(input('Enter value of  r: '))

''' calculate nPr '''

c=n

r1=n-r

for i in range(1,n,1):

    n=n*i

for i in range(1,r1,1):

    r1=r1*i

print('nPr = ',n/r1)

''' calculate nCr '''

for i in range(1,r,1):

    r=r*i

print('nCr = ',n/r1*r)

0 Comments