Tag: 阶乘

无法在C中使用阶乘函数

我无法使用以下代码。 #include // I am not sure whethere I should void here or not. int main() { // when the first bug is solved, I put here arg[0]. It should be // similar command line parameter as args[0] in Java. int a=3; int b; b = factorial(a); // bug seems to be here, since the […]

计算100阶乘的数字总和

编辑 – 更改标题以匹配实际问题陈述。 我正在编写一个计算100中数字总和的函数! 但我似乎有两个大问题。 100的实际结果! 仅对前几个数字准确(实际结果为93326215443944152681699238856266700490715968264381621468592963895217599993229915608941463976156518286253697920827223758251185210916864000000000000000000000000) 我添加结果数字的数字的方法不会输出正确的结果。 这是我目前的代码: void factorialSum() { double fact100 = factorial(100); double suma = 0; printf(“100! is equal to: %.0f”, fact100); while (fact100 > 0) { double temporal = fmod(fact100, 10); suma = suma + temporal; fact100 = fact100/10; } printf(“\nThe sum of all digits in 100! is: %.0f”, suma); […]