C++ Program to display ones complement of a given binary number [DEVCPP/GCC]

PROGRAM

//Program to display ones complement of a given positive binary number 

#include <iostream>

using namespace std;

int main()
{
        int len,i;
        string bin,ones;

        cout<<"ENTER BINARY NUMBER: ";
        cin>>bin;

        len=bin.length();
        ones.resize(len);

        for(i=0;i<len;i++)
        {
                if(bin[i]=='0')
                {
                          ones[i]='1';
                 }
                 else
                 {
                          ones[i]='0';
                 }
        }

        cout<<"\nONE'S COMPLEMENT: "<<ones;
        return 0;
}

OUTPUT

C++ Program to display ones complement of a given binary number with output


Share this

Related Posts

1 comments :

comments
February 15, 2022 at 9:04 AM delete

Sir/mam can we talk with each other because i want help for my blog

Reply
avatar

FIND US ON FACEBOOK!