c求助 这个运行好好的,为交答案就是不对啊

P1009 [NOIP1998 普及组] 阶乘之和

yzqz666 @ 2023-10-28 21:03:20

#include<stdio.h>
int main()
{
    int n;
    scanf("%d",&n);
    int b[10000]={0};
    int last;

    while(n>0)
    {
    int a[10000]={0,1,0};
    int i=1;
    last=1;
    int j=1;
    for(i=1;i<=n;i++)
    {
        for(j=1;j<=last;j++)
        {
            a[j]*=i; 
        }
        for(j=1;a[j]!=0||j<=last;j++)
        {
            a[j+1]+=a[j]/10;
            a[j]=a[j]%10;
        }
        last=j-1;

    }
    int x;
        for(x=1;x<=last;x++)
        {
            b[x]+=a[x];
        }
        for(j=1;b[j]!=0||j<=last;j++)
        {
            b[j+1]+=b[j]/10;
            b[j]=b[j]%10;
        }

    n--;
    }
    int k;
    for(k=10000;k>0;k--)
    {
        if(b[k]!=0)
        {
            break;
        }
    }
    int y;
    for(y=k;y>0;y--)
    {
        printf("%d",b[y]); 
    }
    return 0;
}

by Misophiliac @ 2023-10-28 21:17:03

@ttllww 数组开的时候要多开至少一位


by yzqz666 @ 2023-10-28 21:46:00

@yuanxiuan @yuanxiuan 我感觉我这个数组足够存吧,多开好多啊


by Misophiliac @ 2023-10-28 21:49:06

@ttllww 您在倒数第14行给k赋了10000,所以倒数第12行就用到了b[10000]


by yzqz666 @ 2023-10-28 22:01:35

@yuanxiuan 明白了,感谢感谢


by meiyingbao @ 2024-03-04 16:47:16

@yzqz666 orz orz


by yzqz666 @ 2024-03-04 16:50:28

@meiyingbao 菜就多练,写不起就别写


|