我正在尝试查找 nCr 值。没有错误,但我得到 1 作为所有输入的答案。请帮我找到解决方案。
#include <stdio.h>
int fact(int num)
{
int f=1,i;
for(i=1;i<=num;i++)
{
f=f*1;
}
return f;
}
int main(void)
{
int n,r,ncr=0;
printf("\n enter n and r values");
scanf("%d%d",&n,&r);
ncr=(fact(n) / (fact(r) * fact(n-r)));
printf("\n ncr for %d and %d is %d",n,r,ncr);
return 0;
}
最佳答案
不应该是f = f *1,而是f = f * i
关于c - 寻找 nCr 值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31152318/