【发布时间】:2013-02-09 22:48:26
【问题描述】:
为什么=n! / ((n-k)!*k!) 不打印?
这段代码也能解决下面的问题吗?
卡住了。
"The number of combinations of n things taken k at a time as an integer"
再澄清一点:“例如,a,b,c,d 四个项目一次取三个的组合是 abc,abd,acd,bcd。也就是说,总共有四种不同的四样东西的组合“一次取三样”。”
#include <stdio.h>
#include <math.h>
int main (void)
{
int z = 0, n_in, k_in, k = 0, n = 0, result, nfr = 0, kfr = 0;
do
{
printf("Enter the number of items in the list (n):");
scanf("%d*c", &n_in);
if (n_in>1 && n_in<11)
{
printf("Enter the number of items to choose (k)");
scanf("%d*c", &k_in);
if (k_in>0 && k_in<5)
{
if (k_in <= n_in)
{
k_in = k;
n_in = n;
result = n! / ((n-k)!*k!);
z = 1;
}
else
printf("?Please Try again k must be less than n \n");
}
else
printf("?Invalid input: Number must be between 1 and 4 \n");
}
else
printf("?Invalid input: Number must be between 1 and 10 \n");
} while (z == 0);
result = (nfr / (nfr * kfr));
printf("k value = %d n value = %d the result is %d", nfr, kfr, result);
return 0;
}
【问题讨论】:
-
!不会像您认为的那样做。制作你自己的阶乘函数。 -
在尝试做事之前为什么不学习语言?
-
那将无法编译。从头开始。在执行当前代码之前无需担心打印。
-
到底谁在支持这个废话
-
这是关于一般主题的第三个问题,其他问题是How could I count a sub-range of 1-4 in permutations of a 1-10 digit range 和A simple expression for counting combinations in a range of numbers。这个问题令人担忧;您发布的是非编译代码,而不是您可以得到帮助的 SSCCE (Short, Self-Contained, Correct Example)。您应该注意您的代码无法编译; “不工作”通常表示可以编译但无法运行的代码。
标签: c function combinations