Decimal to Binary Conversion - Learn Engineering

All the news and updates relevant to Engineering. You can also Write a post here

Breaking

Friday, June 26, 2020

Decimal to Binary Conversion

C++ PROGRAM TO CONVERT DECIMAL   NUMBER TO BINARY NUMBER

Sample Test Case    :    Enter the Number : 3

Sample Output    : Binary equivalent of 3 is 11 

CODE

#include<bits/stdc++.h>
using namespace std;
int main()
{
    int num,bin;
    cout<<"Enter the Number :";
    cin>>num;
    cout<<"Binary equivalent of"<<num<<"is :";
    while(num>0)
    {
        bin=num%2;
        cout<<bin;
        num/=2;
    }
    return 0;
}

No comments:

Post a Comment