Basically i wrote a factorial function that works like a charm and planned on using it in this combination function that I wrote. But some of the combinations (nCr) that I need to use have a 0 value for r. This means that somewhere in the calculation I am dividing by zero which gives me an error. I tried to put in an if statement so that if r == 0 to output 1 instead but it is just outputtong random ints instead of 1. Here it is:
instead of getting 1 i am getting 4288548 in my output. Any help would be greatly appreciated.Code:int nCr (int n, int r) { if (r!=0) //if r is not 0 do the calculation and store it. { long double nCr = factl(n)/(factl(r)*factl(n-r)); } else //otherwise store the value 1 instead. { int nCr = 1; } }



LinkBack URL
About LinkBacks


