PROGRAM TO FIND TWO'S COMPLEMENT OF A BINARY NO:
#include<iostream>
#include<string.h>
using namespace std;
main()
{
string s,t;
int carry;
cout<<"ENTER A BINARY NO";
cin>>s;
for(int i=0;i<s.length();i++)
{
if(s[i]=='0')
s[i]='1';
else
s[i]='0';
}
carry=1;
for(int i=s.length()-1;i>=0;i--)
{
if(s[i]=='1'&&carry==1)
{s[i]='0';
}
else if(s[i]=='0'&&carry==1)
{
s[i]='1';
carry=0;
}
}
cout<<s;
}
#include<iostream>
#include<string.h>
using namespace std;
main()
{
string s,t;
int carry;
cout<<"ENTER A BINARY NO";
cin>>s;
for(int i=0;i<s.length();i++)
{
if(s[i]=='0')
s[i]='1';
else
s[i]='0';
}
carry=1;
for(int i=s.length()-1;i>=0;i--)
{
if(s[i]=='1'&&carry==1)
{s[i]='0';
}
else if(s[i]=='0'&&carry==1)
{
s[i]='1';
carry=0;
}
}
cout<<s;
}