Search This Blog

Wednesday, 24 October 2012

Program to find the ncr value using function

#include<iostream.h>
int fact(int);
void main()
{
int n,r,nf,rf,nrf,ncr;
cout<<"Enter n and r values, n should be greater than r:";
cin>>n>>r;
nf=fact(n);
rf=fact(r);
nrf=fact(n-r);
ncr=nf/(rf*nrf);
cout<<"Ncr value is "<<ncr;
}
int fact(int t)
{
int f=1,i;
for(i=1;i<=t;i++)
f*=i;
return f;
}

Output:
Enter n and r values, n should be greater than r: 64
Ncr value is 15

No comments:

Post a Comment