In main, declare 2 int variables n and k. Get input from the user using cin or initialize them when you declare them.
Use a statement like cout << C(n,k)<<endl; which will call your function and output the results returned from the function. Your recursion will take care of all the subsequent calls the main program just sits and waits for the return.
This is the code I currently have after taking your advice I am currently getting 2 warnings and am not sure why.
// This program will contain a recursive function that will compute the binomial coefficient according to the definition if k=0 or k=n
using namespace std ;
int C(int n,int k);
cout<< C(n,k) <<endl;
int C(int n,int k)
if (k < 0 || k > n )
if (k == 0)
if (k == n)
else return C(n -1,k) + C(n -1,k -1);
Edited 6 Years Ago by WaltP: That's twice we've added CODE tags. It's YOUR turn next time
Please use the code tags when posting the code. You're not getting n and k from anywhere so they are undefined. Either prompt the user for them or declare them like int n=5,k=3;. You don't need that first C(n,k); in there on line 15 or so, as your function is being evaluated as part of the statement with cout.
Other little things, you don't need to include <algorithm> since you're not using any of its methods. Instead of System("Pause");use cin.get(). System as call has to halt the program, bring up the OS, run the command, and then bring up your program again. Plus cin.get is portable.
I have a 2d matrix with dimension (3, n) called A, I want to calculate the normalization and cross product of two arrays (b,z) (see the code please) for each column (for the first column, then the second one and so on).
the function that I created to find the ...
Write a C program that should create a 10 element array of random integers (0 to 9). The program should total all of the numbers in the odd positions of the array and compare them with the total of the numbers in the even positions of the array and indicate ...