הייי אני ממש מיואשת וזקוקה נואשות לעזרה!!!
כתבתי תוכנית שמטרתה לחבר בין שני מספרים שהם עד גודל 30. הגדרתי 2 מערכים מסוג CHAR שיקלוט מהמשתמש את שני המספרים..תחילה אני מאפסת את מערכים אלו.
ואז ממירה את המשתנים לINT ומחברת אותם ומכניסה לתוך מערך נוסף.
הפלט נכון אבל מופיעה את השגיאה שהמערך " arr31 was corrupted" מה זה?!?!?
אני מצרפת את הקוד..הוא מסורבל ויש מלא תנאים..הלוואי ומישהו יראה משהו שאני לא ראיתי!!!
for(r3=0;r3<(SIZE3);r3++)
{
final31[r3]=0;
final32[r3]=0;
sum3[r3]=0;
}
for(r3=0;r3<=SIZE3;r3++)
{
arr31[r3]='0';
arr32[r3]='0';
}
printf("Enter first number:\n");
scanf("%s",arr31);
printf("Enter second number:\n");
scanf("%s",arr32);
while (arr31[count31]!='\0') /*count1 is the length of arr1*/
{
count31++;
}
while (arr32[count32]!='\0') /*count2 is the length of arr2*/
{
count32++;
}
if(count31<count32) /*to decide which number will be up and which down*/
{
for(i3=count31-1,j3=count32-1;i3>=0 && j3>=((count32-1)-(count31-1));i3=i3-1,j3=j3-1)
{
final31[i3]=arr31[i3]-'0'; /*transforming from char to int*/
final32[j3]=arr32[j3]-'0';
sum3[j3]=(final31[i3]+final32[j3]+temp3); /*sum of the last matching digits*/
if(sum3[j3]>=10) /*the max value that sum can get is- 9+9=18*/
{
sum3[j3]=(sum3[j3]%10);
temp3=1; /*temp will add to the next two digits sum*/
}
else
temp3=0;
}
for(k3=(count32-count31-1);k3>=0;k3=k3-1) /*k reprsent the numbers in the longest number that dosent has any matching digit in the shorter number*/
{
sum3[k3]=(arr32[k3]-'0')+temp3;
if(sum3[k3]>=10)
{
sum3[k3]=(sum3[k3]%10);
temp3=1;
}
else
temp3=0;
}
counter3=count32-1; /*counter= the length of sum array*/
if(temp3==1)
{temp3=0; /*if the sum of the the two digits last digit (that has the higest value in the number)is higer
than 9 we need to increase the array in one more place*/
for(i3=count31-1,j3=count32-1;i3>=0 && j3>=0;i3--,j3--)
{
final31[i3+1]=arr31[i3]-'0';
final32[j3+1]=arr32[j3]-'0';
sum3[j3+1]=(final31[i3+1]+final32[j3+1]+temp3);
if(sum3[j3+1]>=10)
{
temp32=(sum3[j3+1]/10);
sum3[j3+1]=(sum3[j3+1]%10);
temp3=temp32;
}
else
temp3=0;
}
for(k3=(count32-count31-1);k3>=0;k3=k3-1) /*k reprsent the numbers in the longest number that dosent has any matching digit in the shorter number*/
{
sum3[k3+1]=(arr32[k3+1]-'0')+temp3;
if(sum3[k3+1]>=10)
{
sum3[k3+1]=(sum3[k3+1]%10);
temp3=1;
}
else
temp3=0;
}
sum3[0]=1;
counter3=count32;
}
}
if(count32<count31)
{
for(i3=count31-1,j3=count32-1;i3>=((count31-1)-(count32-1)) && j3>=0;i3=i3-1,j3=j3-1)
{
final31[i3]=arr31[i3]-'0';
final32[j3]=arr32[j3]-'0';
sum3[i3]=(final31[i3]+final32[j3]+temp3);
if(sum3[i3]>=10)
{
sum3[i3]=(sum3[i3]%10);
temp3=1;
}
else
temp3=0;
}
for(k3=(count31-count32-1);k3>=0;k3=k3-1)
{
sum3[k3]=(arr31[k3]-'0')+temp3;
if(sum3[k3]>=10)
{
sum3[k3]=(sum3[k3]%10);
temp3=1;
}
else
temp3=0;
}
counter3=count31-1;
if(temp3==1)
{temp3=0;
for(i3=count31-1,j3=count32-1;i3>=0 && j3>=0;i3--,j3--)
{
final31[i3+1]=arr31[i3]-'0';
final32[j3+1]=arr32[j3]-'0';
sum3[i3+1]=(final31[i3+1]+final32[j3+1]+temp3);
if(sum3[i3+1]>=10)
{
temp32=(sum3[i3+1]/10);
sum3[i3+1]=(sum3[i3+1]%10);
temp3=temp32;
}
else
temp3=0;
}
for(k3=(count31-count32-1);k3>=0;k3=k3-1)
{
sum3[k3+1]=(arr31[k3]-'0')+temp3;
if(sum3[k3+1]>=10)
{
sum3[k3+1]=(sum3[k3+1]%10);
temp3=1;
}
else
temp3=0;
}
sum3[0]=1;
counter3=count31;
}
}
if(count32==count31)
{
for(i3=count31-1,j3=count32-1;i3>=0,j3>=0;i3--,j3--)
{
final31[i3]=arr31[i3]-'0';
final32[j3]=arr32[j3]-'0';
sum3[i3]=(final31[i3]+final32[j3]+temp3);
if(sum3[i3]>=10)
{
sum3[i3]=(sum3[i3]%10);
temp3=1;
}
else
temp3=0;
}
counter3=count32-1;
if(temp3==1)
{
temp3=0;
for(i3=count31-1,j3=count32-1;i3>=0,j3>=0;i3--,j3--)
{
final31[i3+1]=arr31[i3]-'0';
final32[j3+1]=arr32[j3]-'0';
sum3[i3+1]=(final31[i3+1]+final32[j3+1]+temp3);
if(sum3[i3+1]>=10)
{
temp32=(sum3[i3+1]/10);
sum3[i3+1]=(sum3[i3+1]%10);
temp3=temp32;
}
else
temp3=0;
}
sum3[0]=1;
counter3=count32;
}
}
for (i3=0; i3<SIZE3; i3++)
left4[i3]=0;
printf("Answer:\n");
m3=counter3;
while(sum3[m3]==0 && m3>=0)
{
m3--;
}
if(m3<0) /*if the sum is equal to zero*/
printf("0\n");
else
{
for (m3=0;m3<=counter3;m3++)
printf("%d",sum3[m3]);
}
printf("\n");