# Include <iostream>
Using namespace STD;
Int * array_carry_chain (int * a, int * B, int N );
Int main ()
{
Int A [10] = };
Int B [10] = };
// 1001000100
Int * c = array_carry_chain (a, B, 10 );
If (C! = NULL)
{
For (INT I = 0; I <10; I ++)
{
Cout <C [I];
}
}
Return 0;
}
Int * array_carry_chain (int * a, int * B, int N)
{
If (A [0] + B [0]> 1)
{
Cout <"overflow! "<Endl;
A = NULL;
Return;
}
For (INT I = n-1; I> 0; I --)
{
If (A [I] + B [I]> 1)
{
Int J = I;
Do
{
J --; // obtain the location of the first place
// If the carry has reached the highest bit, and the carry overflows
If (j = 0 & A [J] + 1> 1)
{
Cout <"overflow! "<Endl;
A = NULL;
Return;
}
// The first digit of the chain in which the user stores the returned value is 0. The position 1 is not carried.
If (A [J] = 0)
{
A [J] = 1;
Break;
}
// The first digit of the chain in which the user stores the returned value is 1, and the position is 0, then 1 to the second digit
Else if (a [J] = 1)
{
A [J] = 0;
A [J-1] ++;
}
// The first digit of the chain in which the user stores the returned value is 2 (the first digit is 1, and the first digit of the carry is not processed yet), and the position is 0,
// Enter 1 to the next level
Else
{
A [J] = 1;
A [J-1] ++;
}
} While (A [J-1] <= 1 & J-1> = 0 );
// Save the base value after carry
A [I] = A [I] + B [I]-2;
} // If
Else
{
A [I] = A [I] + B [I];
}
}
Return;
}