小编Aks*_*hay的帖子

不精确的C++阶乘程序

我编写了以下教程的实现:LINK

基本上,由于C/C++没有BIG Integer,我们将阶乘十进制值存储在一个数组中.这相当于编写一个乘法,用于执行在学校教授孩子的乘法.

问题:对于高达17的值,它可以正常工作!之后(18!,19!,...)它不会输出正确的值.

#include <iostream>
using namespace std;

int main(){
    int fact[1000]={1};
    int n; scanf("%d", &n); //n are the number of factorials we will calculate
    while(n--){
        int number; scanf("%d", &number);   //scan the number
        if(number == 0) printf("%d", 1);
        int flag = number;
        int index = 0, length = 0;
        //following lines we find the length of the entered number
        while(flag!=0){
            fact[index] = flag%10;
            flag /= 10;
            index++; length++;
        }
        //following lines are the multiplication code
        while(number>1){
            index = …
Run Code Online (Sandbox Code Playgroud)

c++ arrays biginteger factorial

3
推荐指数
1
解决办法
198
查看次数

标签 统计

arrays ×1

biginteger ×1

c++ ×1

factorial ×1