#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
long double fact( int);
int ncr( int ,int);
long npr( int ,int);
main()
{
int n,r;
printf(" Enter value of n & r \n");
scanf("%d %d",&n ,&r);
if( n>= r)
{
printf( "%d C %d is %d \n",n,r,ncr( n ,r));
printf("%d P %d is %ld\n",n,r,npr( n, r));
}
else
{
printf("\n n should be greater than r");
getch ();
}
long double fact( int p)
{
long double facts = 1;
int i;
for( i = 1; i<= p; i++)
facts = facts * i;
return(facts);
}
int ncr ( int n, int r)
{
return( fact( n) / (fact( r) * fact(n- r) ) ) ;
}
long npr( int n ,int r)
{
return( fact( n) / fact( n- r));
}
Search This Blog
Showing posts with label nCr program. Show all posts
Showing posts with label nCr program. Show all posts
Program to Calculate Permutations and Combinations (nPr and nCr)
This is a C program to calculate number of permutations (nPr) and combinations (nCr) for given values of n and r. This program calculates nPr and nCr using functions.
Subscribe to:
Posts (Atom)