There are two n-bit binary integers each stored in arrays A and B. Consider Their addition. The sum of two integers is stored in array C with (n + 1) elements in binary form. Provide a formal description of the problem and write pseudocode.
The following is the c ++ code I wrote. If there is an error, please point it out.
# Include "stdafx. H "# include <iostream> # include <string> # define N 20 using namespace STD; void add (int A [], int B [], int C []) {for (INT I = 0; I <n-1; I ++) {C [I] + = (a [I] + B [I]); if (C [I]> = 2) {C [I + 1] + = C [I]/2; C [I] = C [I] % 2 ;}} c [n-1] + = (a [n-1] + B [n-1]); // process the highest bit if (C [n-1]> = 2) {c [N] + = C [n-1]/2; C [n-1] = C [n-1] % 2 ;}} int _ tmain (INT argc, _ tchar * argv []) {int A [n]; int B [N]; int C [n + 1]; memset (C, 0, sizeof (INT) * (n + 1); For (INT I = 0; I <n; I ++) A [I] = rand () % 2; for (INT I = 0; I <n; I ++) B [I] = rand () % 2; add (A, B, C); Return 0 ;}