English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

2 answers

I guess that you want to write a program for the formula

nCm = n!/((m!)*(n-m)!)

The only thing you need is the code to calculate factorial.

float recurs(int n)
{
if (n<=0) return 1.0;
else return (n*recurs (n-1));
}

As can be seen this is recursive function. You can write non-recursive function by simply having a loop instead.

float recurs(int n)
{
float factorial;
for(int i=1;i<=n;i++)
factorial *=i;
return factorial;
}

Now you can write your program like this.

main()
{

int n,m;
printf("Enter n and m \n");
scanf ("%d %d",&n,&m);
printf("The combination is %f", /
recurs(n)/(recurs(m) * recurs(n-m))
}

2007-02-28 20:56:01 · answer #1 · answered by manoj Ransing 3 · 1 0

A combination of what??????

More details would be helpful.....

2007-03-01 04:56:10 · answer #2 · answered by Martin G. 4 · 0 0

fedest.com, questions and answers