请教各位,为什么输出会有负数?

P1303 A*B Problem

newboy_cdw @ 2016-05-17 11:35:14

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int x[10001]={0},y[10001]={0},z[20001]={0};//一定要加上={0}
char s1[10001],s2[10001];
int main(void)
{
    int i,j,len1,len2,len;
    gets(s1);
    gets(s2);
    len1=strlen(s1);
    len2=strlen(s2);
    for(i=0;i<len1;i++)
         x[len1-i]=s1[i]-48;
    for(i=0;i<len2;i++)
         y[len2-i]=s2[i]-48;
    for(i=1;i<=len1;i++)
         for(j=1;j<=len2;j++)
         {
              z[i+j-1]+=x[i]*y[j];
              if(z[i+j-1]>=10)
              {
                   z[j+i]+=z[j+i-1]/10;
                   z[j+i-1]=z[j+i-1]%10;
              }
         }
    len=20001;
    while(z[len]==0&&len>1)
         len--;
    for(i=len;i>=1;i--)
         printf("%d",z[i]);
return 0;
}

by gt2004119 @ 2016-10-20 21:29:22

哈哈哈

######_>- 0. _


|