I'm trying to implement some sort of a two's complement algorithm in C++ and so far I think my logic is correct. However, I get the following error when I run it invalid types 'int[int]' for array subscript
#include <iostream>
#include <stdio.h>
using namespace std;
int main(){
int a[4] = {0, 2, 3, 5};
int b[4] = {9, 7, 8 ,4};
int sum = 0;
int transmit = 0;
int c{0};
for (int k=3;k>0;k--){
sum = a[k]+b[k]+transmit;
c[k+1]=sum%10;
transmit=sum/10;
}
c[0] = transmit;
return 0;
}
I guess your purpose is to do plus operation of two int arrays? A little explanation: you have to declare five units for 'c' as there may be one additional carrier (you called transmit)
With this format: array of decimal integers, they are somewhat hard to be converted to a binary directly. But I can still try to give out a solution:
The full program: