I am taking a C programming course. We are writing our third program, and I do not understand exactly what to do. :confused: I don't want someone to do my homework, but I need an explanation of this so that I can work it out. This is copied directly from our homework.
In order to calculate the binomial coefficients, a mathemetician developed pasc(k, j), a physicist developed coeff(k, j), and an engineer developed approx(k, j). Here we are assuming k >= j. Evaluate which of these is the best to use and explain why. Write a program that calculates the values of these functions at any input value of k and j. The main function should have a loop allowing the user to continue to enter values of k and j until they decide to quit. If the user enters negative numbers, or if they enter values k and j with k < j, you must not accept the values, and instead prompt them again for positive whole numbers with k >= j. Include global variables that count the number of times each function is called when an evaluation is made. These counters are to be imcremented in the very first statement of pasc and approx, but is to incremented as the first statement in fact to measure coeff. The values of these counters are to be output as a (partial) measurement of efficiency.
long pasc(int k, int j);
float approx(int k, int j);
long coeff(int k, int j);
1, if j == 0
1, if k ==j
pasc(k-1, j-1) + pasc(k-1, j), otherwise
k, if k==j
((k-j+1)/j) * approx(k, j-1), otherwise
Could you please explain a little more? I am very, very new at this. What is pasc, coeff, and approx? What is a binomial coefficient? What is the difference between imcrementing in the very first statement and incrementing as the first statement in fact? I also don't understand the Descriptions we were given.
Thank you so much for what you've given me already.
> What is a binomial coefficient?
> pasc(k, j)
> 1, if j == 0
> 1, if k ==j
> pasc(k-1, j-1) + pasc(k-1, j), otherwise
Function pasc takes two variables, k and j. If j == 0 or if k == j, the function returns 1. Otherwise the function returns pasc(k-1, j-1) + pasc(k-1, j), which is a recursive call.
> coeff(k, j)
Function coeff takes two variables, k and j. Then it uses a function fact() to calculate the return value. The function fact() will be the factorial, since we are talking about binomial coefficients here.
> approx(k, j)
> k, if k==j
> ((k-j+1)/j) * approx(k, j-1), otherwise
Function approx takes two variables, k and j. If k == j, the function returns k, else the function returns ((k-j+1)/j) * approx(k, j-1), again recursion is used.
Recursion for programming:
Thank you, everyone who helped, very much .