Write one java program that in three different ways calculates the binomial coefficients
Answers
Answered by
0
I have 2 parameters and I want the method to return an int result.. I was given this code but I don't understand naff all about binoms etc and don't know how to "convert" it has double BC[126][126]; defined somewhere above it. But i don't need that i just want a result for these n and m. (I probably sound like numpty for putting like that)
private void binom(int n, int m) { int i, j; if (n>=0) if (m>n||m<0) System.err.println("Illegal m!!\n"); else { for(i=0;i<=n;i++) BC[i][0] = 1; for(i=1;i<=m;i++) BC[0][i] = 0; for(j=1;j<=m;j++) for(i=1;i<=n;i++) BC[i][j] = BC[i-1][j-1] + BC[i-1][j]; } else System.err.println("Negative n!!\n"); }
private void binom(int n, int m) { int i, j; if (n>=0) if (m>n||m<0) System.err.println("Illegal m!!\n"); else { for(i=0;i<=n;i++) BC[i][0] = 1; for(i=1;i<=m;i++) BC[0][i] = 0; for(j=1;j<=m;j++) for(i=1;i<=n;i++) BC[i][j] = BC[i-1][j-1] + BC[i-1][j]; } else System.err.println("Negative n!!\n"); }
Similar questions
Chemistry,
7 months ago
Geography,
7 months ago
English,
7 months ago
Computer Science,
1 year ago
Computer Science,
1 year ago