Write a program which inputs n and r and computes nCr by calling the
function which returns the factorial of its argument. The function computes
the factorial by using recursive method.
nCr = n! / r! (n-r)!
#include
#include
float nfac(float);
float rfac(float);
float n_rfac(float);
void main()
{
float n,r,n_r,fn=1,fr=1,fn_r=1,ncr;
clrscr();
printf("Enter n");
scanf("%f",&n);
printf("Enter r");
scanf("%f",&r);
n_r=n-r;
fn=nfac(n);
fr=rfac(r);
fn_r=n_rfac(n_r);
ncr=fn/(fr*fn_r);
printf("\n%.0fC%.0f=%.0f!/(%.0f!*%.0f!)",n,r,n,r,n_r);
printf("\n==> %.0f / (%.0f * %.0f)",fn,fr,fn_r);
printf("\n==>nCr=%f",ncr);
getch();
}
float nfac(float n)
{
float i,fcn=1;
for(i=1;i<=n;i++)
fcn*=i;
return(fcn);
}
float rfac(float r)
{
float i,fcr=1;
for(i=1;i<=r;i++)
fcr*=i;
return(fcr);
}
float n_rfac(float n_r)
{
float i,fcn_r=1;
for(i=1;i<=n_r;i++)
fcn_r*=i;
return(fcn_r);
}
/* Output
Enter n3
Enter r3
3C3=3!/(3!*0!)
==> 6 / (6 * 1)
==>nCr=1.000000
*/
Shopping In MUMBAI
Are you searching for Discounts, offers, sale in Mumbai ? You are in the right place. MUMBAI, a shopping haven, has no dearth of great discounts and sales. This blog features the best MUMBAI shopping offers, sale, discounts and deals and bargains CURRENTLY GOING on in Mumbai plus a few free things thrown in on top.
Don't wait for it because once they are gone, they are gone. Hurry!..By clicking the "Like" button you will receive a daily update of discounts, sale, offers going on in Mumbai. LIKE IT.... SHARE IT...njoY.
Wednesday, December 31, 2008
C program which inputs n and r and computes nCr ie nCr = n! / r! (n-r)!
Posted by ars at 11:17 AM
Subscribe to:
Post Comments (Atom)
0 comments:
Post a Comment