Skip to main content
gamedev.net
🔒 Locked

binomial coefficients

Started by matt0r Nov 3, 2004 at 9:27 PM 1 replies 550+ views
Original Post
matt0r
matt0r
public static int nonRecursive(int n, int k)
{
  int[] b = new int [n + 1];
        b [0] = 1;
        for (int i = 1; i <= n; ++i)
        {
            b  = 1;
            for (int j = i - 1; j > 0; --j)
                b [j] += b [j - 1];
        }
        return b [k];

 }
rewrite this without using arrays or recurssion
iMalc
iMalc
What are we, your slaves? If you're gonna put it that way...

DIY, unless you'd like to politely ask for help and it isn't homework (looks to me like it is).
Krumble
Krumble
To calculate a binomial coefficient you need to calculate 3 factorials, which can be done with 3 loops. Beware of overflow though.
Kevin.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.