//programme to find BINOMIAL COEFFICIENT - formular - n!/k!(n-k)!
#include<iostream>
#include<cstdlib>
usingnamespace std;
bool validateInput(int n, int k); //prototype the functions
int getfactorial(int n); //prototype the functions
int main()
{
int n,k,y;
cout<<"Enter \'N\' and \'K\' "<<endl;
cin>>n>>k;
if(validateInput(n,k)==1) //valid the values that user has input
{
//calling fuctions and apply the formular
y = getfactorial(n)/(getfactorial(k)*getfactorial(n-k));
cout<<"ANSWER IS : "<<y<<endl;
}
else
{
cout<<"INVALID INPUTS, PLEASE RE-START THE PROGRAMME!"<<endl;
system("PAUSE");
return -1;
}
system("PAUSE");
return 0;
}
bool validateInput(int n, int k) //functions to check Inputs
{
bool result;
if((n>0)&&(k>0)&&(k<n))
{
result = 1;
}
else
{
result = 0;
}
return result;
}
int getfactorial(int n)//Function to get FACTORIALS
{
int f=1;
for(int i = 1; i<=n; )
{
f=f*i;
i++;
}
return f;
}
This is my 1st post. i am still learning c++, i am very happy to if you can receive some good programming practices.
here its done now.. i correct some of my coding mistakes... i only test one value previously, that why i am not caught this i think :-D! thanks for the mentioning!