C Program to Find Permutations (npr) and Combinations (ncr) Value

Find nPr(Permutation) and Combination (nCr) using C Program with example

In probability and statistics Permutation Combination most commonly used terms. Formula to find permutation is nPr = n!/(n-r)! and formula to find Combination is nCr = n!/(r!(n-r)!) we can say ncr=nPr/r!.
So in C program first we need to get input for n,r from user and calculate the factorial value for n,r, n-r. So now just apply the factorial result to the above permutation, combination formulas to get the result.
The Below example C code will calculate the permutation and combination value.

#include <stdio.h>

void main(void)
int n,r;
printf("Enter value for n:\n");
printf("Enter value for r:\n");
int nf=fact(n);
int rf=fact(r);
int nrf=fact(n-r);
int npr=nf/nrf;
int ncr=npr/rf;
printf("Permutation and Combination values\n");
printf("nCr=%d \n nPr= %d",ncr,npr);

int fact(int n){
if(n <= 1)
return 1;
return n * fact(n - 1);

You can also check the result with the online Permutation Combination Calculator

Related Topic Java Program / Code for Broken link finder
Basic Linux Commands
Array Search in Java
Java String Replace Regex
How to Calculate Day Difference between Date

nScraps.com 2011   Privacy Policy  Terms of Service  Feedback