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 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)


Write a Program in lisp to find remainder?

Here's a simple program in Lisp to find the remainder of two numbers using the mod function: (defun find-remainder (a b) (mod a b)) ;; Example usage: (find-remainder 10 3) ; This will return 1 This function find-remainder takes two arguments, a and b, and returns the remainder of a divided by b.


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

The number of function is Geometry


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.


How can you program a TI-83 Plus to find area under a curve?

To program a TI-83 Plus to find the area under a curve, you can use the built-in integration functionality. Start by entering the function you want to integrate using the Y= menu. Then, create a new program by accessing the PRGM menu, selecting NEW, and entering your program name. In the program, use the fnInt command to calculate the integral, specifying the function, variable, lower limit, and upper limit. Finally, display the result using the Disp command.


output of a c program using function to find factorial of a number?

In a C program that calculates the factorial of a number using a function, the program typically prompts the user for an integer input. The function then recursively or iteratively computes the factorial by multiplying the number by the factorial of the number minus one until it reaches one. For example, if the user inputs 5, the program outputs 120, as 5! = 5 × 4 × 3 × 2 × 1. The final result is displayed on the screen.


Explain How do you use a graph to find the output value of a linear function for a given input value?

To find the output value of a linear function for a given input value using a graph, first locate the input value on the x-axis. Then, trace a vertical line upwards from that point until it intersects the line representing the linear function. Finally, from the intersection point, move horizontally to the y-axis to read the corresponding output value. This process visually demonstrates the relationship between the input and output in the function.


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.


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.


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

program to find maximum of two numbers using pointers