[英]This is giving inaccurate results for inputs
Program for finding factorial of a number is providing inaccurate output for the input >20.用于查找数字阶乘的程序为输入 >20 提供不准确的 output。
#include <iostream>
using namespace std;
int main()
{
unsigned int i,p;
unsigned long int f=1;
cout<<"Enter Number : "<<endl;
cin>>i;
for (p=i;p>1;p-=2){
f=f*p*(p-1);
}
cout<<"Factorial is \n"<<f;
}
20. is 2.43*10^18 which is a lot greater than unsigned long int. 20. 是 2.43*10^18,比 unsigned long int 大很多。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.