计算最大数字的阶乘
Calculate factorial of the largest numbers
我想计算大于 30 的数字的阶乘,当我想计算阶乘时结果为 0 。
#include <iostream>
using namespace std;
void fun1();
int main()
{
fun1();
}
void fun1(){
int x ;
int sum = 1 ;
cout << "Enter your number:";
cin >> x ;
if ( x >= 1 ){
for ( int i = x ; i > 1 ; i--){
sum *= i ;
}
}
cout << "Factorial of " << x << " is :" << sum ;
}
您可以使用更大的数据类型(如果可用,unsigned long long int
(。
您可以通过检查表达式中何时有 2 和 5 因素来欺骗一些数字,删除它们并记住在末尾输出额外的 0:
6! = 6 * 5 * 4 * 3 * 2 = ( 6 * 4 * 3 ) * (5*2) = "72""0"
最重要的是,您使用"大数"或"任意精度"库
相关文章:
- 在 C++ 中的数组上使用阶乘函数
- 阶乘问题在 c++ 中给出错误的输出
- 大数的阶乘给出错误的输出
- 什么模板用法在阶乘中更好
- 为什么我在C++阶乘函数中出现编译错误?
- 计算阶乘的 C++17 倍表达式中的错误
- 为什么 Lisp 中 1000 阶乘的计算如此之快(并显示正确的结果)?
- 在C++中执行 N 阶乘编译时间的 3 种不同/相同方法
- 平方模型为零,阶乘模型问题
- 阶乘元规划
- 阶乘-c++ 我想以不同的方式打印
- 阶乘函数只返回C++中输入的答案
- 计算最大数字的阶乘
- 带有自定义数字的阶乘函数不起作用
- N 阶乘中有多少位数字
- 在 C++ 中,数字阶乘的自写代码中的错误
- 程序以查找数字的阶乘并为负整数输入提供错误消息
- c++中带字符串的大数字的阶乘
- Ruby程序:在一个数字的阶乘的n次幂后面加零
- 是否有可能在编译时计算数字的阶乘,但不使用枚举?