The program posted by mayur can be simplified further..
His program calculates n!,(n-r)! and r!.then it does further multiplication and division
If you observe the term n!/(n-r)! it can be written as n(n-1)..(n-r+1)(n-r)!/(n-r)! which reduces to n(n-1)..(n-r+1)
thus if we calculate the above term , calculate r! and divide above term by r! we will have the answer in little less calculations!!
Here is the C program for it…..
#include<stdio.h> float nCr(int n,int r) { int num=1,den=1,i; for(i=1;i<=r;i++) //calculates r! den*=i; for(i=n;i>=n-r+1;i--) //calculates n(n-1)..(n-r+1) num*=i; return (float)num/(float)den;//returns n(n-1)..(n-r+1)/r!=nCr } void main() { int n,r; clrscr(); printf("Enter value of n and r for nCr computation"); scanf("%d%d",&n,&r); printf("\nThe value of %dC%d is %f",n,r,nCr(n,r)); getch(); }