c and c++
always runtime error (SIGSEGV) problem!
but i test so many numbers and the answer is ok!
could anyone know what happened?
this is my code…
#include<stdio.h>
#include <stdlib.h>
#include <string.h>
int main(){
int n;
char mul1[10000],mul2[10000];
char copymull[10000],copymul2[10000];
int result[20003];
memset(copymull,0,10000);
memset(copymul2,0,10000);
memset(result,0,20003);
scanf("%d",&n);
while(n>0)
{
scanf("%s %s",&mul1,&mul2);
int len1 =strlen(mul1);
for(int i=len1-1; i>=0; --i)
copymull[len1-i-1]=mul1[i]-'0';
int len2 =strlen(mul2);
for(int i=len2-1; i>=0; --i)
copymul2[len2-i-1]=mul2[i]-'0';
for(int i=0; i<len1;i++)
for(int j=0;j<len2;j++)
result[i+j]+=copymull[i]*copymul2[j];
for(int i=0 ;i<len1+len2+1;i++)
{
int temp=result[i];
result[i]=temp%10;
result[i+1]+=temp/10;
}
for(int i=len1+len2+1;i>=0;i--)
{
if((result[i])!=0)
{
for(int j=i;j>=0;j--)
printf("%d",result[j]);
printf("\n");
break;
}
if((result[i])==0&&i==0)
{
printf("0");
printf("\n");
break;
}
}
memset(copymull,0,10000);
memset(copymul2,0,10000);
memset(result,0,20003);
n=n-1;
}
}