Hi I just started learning C++ program last week and I was trying to figure out the C++ program code for a combination program. I did this and my logic seem to be right to me but I think I cant work this way:
#include <iostream>
usingnamespace std;
int main (int argc, char * const argv[]) {
// insert code here...
long n,r,a,b,c,d,e;
cout << "Please Enter the number (N) for combination C(N,r): " ;
cin >> n;
cout << " Please Enter your r";
cin >> r;
for (int i=1; i<=n; i++) {
a=a*i;
}
cout << " Your N! value is " << a <<endl ;
b= n-r;
for (int j = 1; j <=b; j++) {
c=c*j;
}
cout << " Your (N-r)! valuse is " << c << endl;
for (int k =1; k <=r; k++) {
d=d*k;
}
cout<< "Your value or r! is " << d<< endl;
e= a/(d*c);
cout<<" The required way on how combinations can be done is" << e<< endl;
return 0;
}
Global Variables, if not initialized, automatically are given the value of zero. Local variables that are not initialized are filled with garbage, random numbers that are highly ineffectual.
You might want to initialize each of your variables by giving them values.
Here's an example
int r = 0;
The rest is pretty straight forward. I gave you a huge hint, right there. Good Luck!