Compliment of a decimal number
#include<iostream>
#include<conio.h>
using namespace std;
int main()
{
int num,n=1,m,cmp;
cout<<"Enter a decimal number : ";
cin>>num;
m=7;
while(num<=m||num>m)
{ int value=1;
if(num<=m)
{
cmp=m-num;
cout<<"Compilment is : "<<cmp;
return 0;
}
n=n+1;
for(int i=0;i<n;i++)
value=value*2;
m=value-1;
}
getch();
}
#include<conio.h>
using namespace std;
int main()
{
int num,n=1,m,cmp;
cout<<"Enter a decimal number : ";
cin>>num;
m=7;
while(num<=m||num>m)
{ int value=1;
if(num<=m)
{
cmp=m-num;
cout<<"Compilment is : "<<cmp;
return 0;
}
n=n+1;
for(int i=0;i<n;i++)
value=value*2;
m=value-1;
}
getch();
}
Binary Number of 61 = 111101
Compliment = 000010 = 2