Stuck in this question .I cant spot where i am doing the mistake. Can somebody help me please. thanks.
this is the question:
-----------------------------------------------
The number of combinations (C) from M items taken N at a time is given by
C= fac(M) / [fac(N) * fac (M – N)]
where fac(X) = X * (X – 1) * (X - 2) * … * 2 *1
Write a function to evaluate fac(X) and incorporate it in a progam to request input
values M and N and calculate C.
===============================================
Below is my code. I have done 3 recursive functions that i want to recall and place in the formula. i also made X represent M-N. finally i wanted to print the result of c. But as I am still learning i am obviously doing lots of mistakes.Sorry about that. please have a look at the code for where i am wrong. thanks.Or maybe the whole code is wrong. please let me know. Thanks.
#include <iostream>
using namespace std;
int M(int m);
int N(int n);
int X(int x);
int main()
{
int m,n,x,c;
cout << "Please enter value of M: "<<M(m)<<endl;
cin>>m;
cout << "Please enter value of N: "<<N(n)<<endl;
cin>>n;
x=(m-n);
c=(M(m)/(N(n)*X(x));
cout << "Calculated value of C is :"<<c<<endl;
return 0;
}
int M(int m)
{
int answerm;
if(m==1)
return(1);
answerm = M(m-1)*m;
return(answerm);
}
int N(int n)
{
int answern;
if(n==1)
return(1);
answern = N(n-1)*n;
return(answern);
}
int X(int x)
{
int answerx;
if(x==1)
return(1);
answerx = X(x-1)*x;
return(answerx);
}