Home > Back-end >  1 (a guide so why write error). Implementation and no more than a 100 - bit long integer addition. F
1 (a guide so why write error). Implementation and no more than a 100 - bit long integer addition. F

Time:10-10

 # include 
#include
Int length (char []);
Void number (char [], char []);
Int main ()
{
[100] char a, b [100], c [100];
Cout<& lt;" Please enter a: ";
Cin> a;
Cout<& lt;" Please input b: ";
Cin> b;
Number (a, b);
return 0;
}

Int length (char [] a)
{
for(int i=0; i<100; I++)
{
If (a [I]=='\ 0')
break;
}
return i;
}

Void number (char [], a char [] b)
{
int i;
Int, over temp.
Int x=length (a);
Int y=length (b);
Int j=x, k=y;
If (x> Y)
I=x;
The else
I=y;
Char c [100]={0};
If (x==y)
{
for(; I> 0; -- - I, j, k -)
{
Temp=[j - 1) + b [k - 1) + over - '0';
C=\ [I + 1] % 10;
Over=temp/10;
}
Cout<& lt; C;
}
Else if (x> Y)
{
for(; I> 0; -- - I, j, k -)
{
While (i> X, y)
{
Temp=[j - 1) + b [k - 1) + over - '0';
C=\ [I + 1] % 10;
Over=temp/10;
}
Temp=a [1] + over - '0';
C=\ [I + 1] % 10;
Over=temp/10;
}
Cout<& lt; C;
}
The else
{
for(; I> 0; -- - I, j, k -)
{
While (i> X, y)
{
Temp=[j - 1) + b [k - 1) + over - '0';
C=\ [I + 1] % 10;
Over=temp/10;
}
Temp=b [k - 1) + over - '0';
C=\ [I + 1] % 10;
Over=temp/10;
}
Cout<& lt; C;
}
}

CodePudding user response:

Wrong too much, logic also too complicated, and error
For example,
Temp=[j - 1) + b [k - 1) + over - '0'; Want to add should actually be
Temp=[j - 1) + b [k - 1) + over - 2 x '0'
  • Related