C中的Pascal三角形组合
#include <stdio.h>
long factorial(int num)
{
int counter;
int fact = 1;
for (counter = num; counter > 0; counter--) fact *= counter;
return fact;
}
float combinations(int n, int k)
{
int numerator = factorial(n);
int denominator = factorial(k) * factorial(n-k);
float fraction = numerator/denominator;
return fraction;
}
int main()
{
printf("How many rows of Pascal's triangle should I print?t");
int rows = GetInteger();
int counter;
int counter2;
for (counter = 1; counter <= rows; counter++)
{
int y = rows-counter;
for (; y > 0; y--) printf(" ");
for (counter2 = 0; counter2 <= counter; counter2++)
printf("%6.0lu", (long) combinations(counter, counter2));
printf("n");
}
}
每次我超过十二行,数字开始减少。我究竟做错了什么?
并且,GetInteger()
只是一个scanf()
,只有一些修饰。我百分百肯定它完美无缺。
没有找到相关结果
已邀请:
3 个回复
桔适丛
门锑腺潮
薄扩络拜
返回1,932,053,504(= 6,227,020,800 - 4,294,967,296)