Explanation

This is a discussion on Explanation within the C Programming forums, part of the General Programming Boards category; I am taking a C programming course. We are writing our third program, and I do not understand exactly what ...

  1. #1
    Registered User
    Join Date
    Mar 2003
    Posts
    3

    Question Explanation

    I am taking a C programming course. We are writing our third program, and I do not understand exactly what to do. 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.

    Prototypes:
    long pasc(int k, int j);
    float approx(int k, int j);
    long coeff(int k, int j);

    Descriptions:
    pasc(k, j)
    1, if j == 0
    1, if k ==j
    pasc(k-1, j-1) + pasc(k-1, j), otherwise

    coeff(k, j)
    (fact(k))/(fact(j)fact(k-j))

    approx(k, j)
    k, if k==j
    ((k-j+1)/j) * approx(k, j-1), otherwise

  2. #2
    Registered User
    Join Date
    Mar 2003
    Posts
    3
    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.

  3. #3
    ....
    Join Date
    Aug 2001
    Location
    Groningen (NL)
    Posts
    2,386
    > What is a binomial coefficient?

    http://mathworld.wolfram.com/BinomialCoefficient.html

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

    http://mathworld.wolfram.com/Recursion.html

    > coeff(k, j)
    > (fact(k))/(fact(j)fact(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.

    http://mathworld.wolfram.com/Factorial.html

    > 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:
    http://personal.vsnl.com/erwin/recursion.htm

  4. #4
    Registered User
    Join Date
    Mar 2003
    Posts
    3

    Smile

    Thank you, everyone who helped, very much .

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Linked Lists
    By Bleu_Cheese in forum C++ Programming
    Replies: 13
    Last Post: 12-21-2007, 09:17 PM
  2. Explanation of switch statements
    By ammochck21 in forum C++ Programming
    Replies: 6
    Last Post: 11-04-2006, 02:59 PM
  3. printf function explanation
    By vice in forum C Programming
    Replies: 3
    Last Post: 09-21-2005, 09:35 PM
  4. basic linked list declaration..need explanation
    By aspand in forum C Programming
    Replies: 3
    Last Post: 06-07-2002, 06:55 PM
  5. Explanation!!!
    By MITCHELL in forum Windows Programming
    Replies: 4
    Last Post: 10-25-2001, 02:13 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21