Menu Close

Permutation and Combination | Fortran

program p_c
implicit none
INTEGER::n,r,fact,p,c


PRINT *, '============================================'
PRINT *, 'CALCULATING NO. OF PERMUTATION & COMBINATION [BOTTOMSCIENCE.COM]'
PRINT *, '============================================'

!CALCULATING NO. OF PERMUTATION & COMBINATION

print *, 'Enter the values of n and r'
read(*,*) n,r

p=(fact(n))/fact(n-r)

print *,"Number of Permutations without repetition are: ", p

c=(fact(n))/(fact(r)*fact(n-r))

print *,"Number of Combinations without repetition are: ", c

end program

!FACTORIAL FUNCTION
INTEGER function fact(n1)
INTEGER::n1,fact1

fact1=1
do i1=1,n1
fact1=fact1*i1
end do

fact=fact1
return
end function

OUTPUT

============================================
CALCULATING NO. OF PERMUTATION & COMBINATION [BOTTOMSCIENCE.COM]============================================
Enter the values of n and r
5
2
Number of Permutations without repetition are: 20
Number of Combinations without repetition are: 10

More Related Stuff