您好,欢迎访问一九零五行业门户网

二项式系数表的C程序

given with a positive integer value let’s say ‘val’ and the task is to print the value of binomial coefficient b(n, k) where, n and k be any value between 0 to val and hence display the result.
what is binomial coefficientbinomial coefficient (n, k) is the order of choosing ‘k’ results from the given ‘n’ possibilities. the value of binomial coefficient of positive n and k is given by
$$c_k^n=\frac{n!}{(n-k)!k!}$$
where, n >= k
example的中文翻译为:示例input-: b(9,2)output-:
$$b_2^9=\frac{9!}{(9-2)!2!}$$
$$\frac{9\times 8\times 7\times 6\times 5\times 4\times 3\times 2\times 1}{6\times 5\times 4\times 3\times 2\times 1)\times 2\times 1}=\frac{362,880}{1440}=252$$
what is binomial coefficient tablethe binomial coefficient table is formed for calculating the multiple values that can be generated between n and k.
example的中文翻译为:示例input-: value = 5output-:
approach used in the below program is as follows −
input the variable ‘val’ from the user for generating the tablestart the loop from 0 to ‘val’ because the value of binomial coefficient will lie between 0 to ‘val’apply the formula given, if n and k is not 0
b(m, x) = b(m, x - 1) * (m - x + 1) / x
print the resultalgorithmstartstep 1-> declare function for binomial coefficient table int bin_table(int val) loop for int i = 0 and i <= val and i++ print i declare int num = 1 loop for int j = 0 and j <= i and j++ if (i != 0 && j != 0) set num = num * (i - j + 1) / j end print num end print
step 2-> in main() declare int value = 5 call bin_table(value)stop
example的中文翻译为:示例#include <stdio.h>// function for binomial coefficient tableint bin_table(int val) { for (int i = 0; i <= val; i++) { printf("%2d", i); int num = 1; for (int j = 0; j <= i; j++) { if (i != 0 && j != 0) num = num * (i - j + 1) / j; printf("%4d", num); } printf("
"); }}int main() { int value = 5; bin_table(value); return 0;}
输出
以上就是二项式系数表的c程序的详细内容。
其它类似信息

推荐信息