C++ 计算最大数的阶乘
我想计算大于30的数字的阶乘,当我想计算阶乘时,结果是0C++ 计算最大数的阶乘,c++,C++,我想计算大于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 ){
#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 ;
}
#包括
使用名称空间std;
void fun1();
int main()
{
fun1();
}
void fun1(){
int x;
整数和=1;
cout>x;
如果(x>=1){
对于(int i=x;i>1;i--){
总和*=i;
}
}
cout您可以使用更大的数据类型(无符号long-long-int
如果可用)
只要表达式中有2和5个因子,就可以通过检查这些因子,删除它们并记住在末尾额外输出一个0来骗取一些数字:
6! = 6 * 5 * 4 * 3 * 2 = ( 6 * 4 * 3 ) * (5*2) = "72""0"
最好是使用“大数字”或“任意精度”库related/dupe: