1's compliment of decimal number to binary number program in c++

Algorithm->step1 start

Step 2Int rem;

If (num <= 1) {

 Cout << !num;

 Return; }Rem = num % 2;

 Onescomp(num / 2);

 Cout << !rem;}

**************Code**********"*"****"******

#include<iostream>

using namespace std;

void onescomp(int num)

{

    int rem;

    if (num <= 1)

    {

        cout << !num;

        return;

    }

    rem = num % 2;

    onescomp(num / 2);

    cout << !rem;

}

int main()

{

    int dec, bin;

    cout << "Enter the number : ";

    cin >> dec;

    if (dec < 0)

        cout << dec << " is not a positive integer." << endl;

    else

    {

        cout << "The ones complement form of " << dec << " is ";

        onescomp(dec);

        cout << endl;

    }

    return 0;

}


Comments

Popular Posts