C++ code for decimal to binary number

 C++ code for decimal to binary number

 

#include<iostream>

using namespace std;
int main()
{
    int decimalNum, binaryNum[20], i=0;
    cout<<"Enter the Decimal Number: ";
    cin>>decimalNum;
    while(decimalNum!=0)
    {
        binaryNum[i] = decimalNum%2;
        i++;
        decimalNum = decimalNum/2;
    }
    cout<<"\nBinary Value: ";
    for(i=(i-1); i>=0; i--)
        cout<<binaryNum[i];
    cout<<endl;
    return 0;
}

Algorithm step1 start

Step 2 enter value

Step3 While(d!=0) { B[i] = d%2;I++; D = d/2;

Step4For(i=(i-1); i>=0; i--) Cout<<b[i];

Step 5 stop


Comments

Popular Posts