The program adds two binary numbers in two' s complement ignoring the overflow for a constant size of bits. I am trying to generalize the program by taking input from the user in a single line without memory wastage. Is there any way to achieve this?
#include<iostream.h>
#include<conio.h>
void main ()
{
const int size=9;
enum bool {a=0, b=1};
bool carry,dummy;
bool array[size]={0,0,1,1,1,1,1,0,1};
bool reg[size]= {1,0,1,1,1,0,1,0,1};
for (int i=(size-1); i>=0 ; i--)
{
dummy=reg[i];
reg[i]= (!reg[i]) && (array[i] !=carry) || reg[i] && (array[i]==carry);
carry=(array[i]&&dummy) || (dummy&&carry) || (array[i]&&carry);
}
for (int j=0 ; j<size ; j++)
{
cout<<reg[j];
}
}