answersLogoWhite

0

/*

* Purpose : Calculate the factorial of a number

* Inputs : int x -- the number of interest

* Outputs : x! if x is non-negative, -1 otherwise

*/

int factorial (int x)

{

int x_factorial = x;

if (x > 0)

{

while (x > 1)

{

x_factorial *= --x;

}

return x_factorial;

}

else if (x = 0)

return 1;

else

return -1;

}

/*

* Purpose : Calculate the binomial coefficient nCr

* Inputs : int n -- the set size

* int r -- how many to choose

* Outputs : The binomial coefficient nCr if r is valid, -1 otherwise

*/

int nCr (int n, int r)

{

if (r >= 0 && n >= r)

return factorial(n) / (factorial(r) * factorial(n - r));

else

return -1;

}

User Avatar

Wiki User

16y ago

What else can I help you with?

Related Questions

How do you write a c program to find area of rectangle using function?

There will be a function in it like this: double RectangleArea (double a, double b) { return a*b; }


How do you find the value of a number in a function?

The number of function is Geometry


How do you find the x value of an equation if you are only given the value of y using function notation?

You use the inverse function (if one exists).So, if y = f(x) then x = f-1(y)


How do you write a c program to find square of a no using call by value?

int square (int N) return N*N;


What function finds the smallest value in a list of numbers in Excel?

You can use the MIN function or you can use the SMALL function, using 1 as the second argument in it. So to find the lowest value in the cells from A2 to A16 the function choices are: =MIN(A2:A16) =SMALL(A2:A16,1) MIN would be more commonly used for the lowest value, but using SMALL you can get the second smallest by changing the 1 to 2, or the third lowest by using 3 and so on.


What is the difference between IF function VLOOKUP function?

The IF function checks a condition to determine a task to do. It is a logical function. VLOOKUP is a lookup function. It can search through a list to find a value or a position in a range, and then find a corresponding value. There are situations where both could be used. Sometimes a VLOOKUP is good for using in place of a nested IF that is having to search through a lot of options. See the related questions below.


How do you find critical value for a total revenue function?

If it is a differentiable function, you find the value at which its derivative is 0. But in general, you can plot it as a line graph and see where it peaks.


How to write a C program to find largest 2 numbers using pointers?

program to find maximum of two numbers using pointers


Can somebody give me the program to find simple interest using friend function in c plus plus?

Here is an example program: class obj{ public: float p,n,r,si; friend void calc( obj temp); }; void calc( obj temp){ si = (p*n*r)/100; } The initialization and function calling is essential.


What is the result of substituting a value for a variable in a function?

To find the value of the other variable


How can you use the initial value theorem to solve for the initial slope of a function?

I suggest: - Take the derivative of the function - Find its initial value, which could be done with the initial value theorem That value is the slope of the original function.


How do you find the y-intercept of a function?

The y-intercept is the value of a function f when x is equal to zero. So, substitute 0 for x into the equation and find the value of y.