Programming Examples
Cpp program to convert decimal number to binary
Write a program to convert decimal number to binary.
#include<iostream>
using namespace std;
int main(){
int decimal,binary=0,base=1 ;
cout<<"Enter any number:";
cin>>decimal;
while(decimal>0){
int digit=decimal%2;
binary+=digit*base;
decimal/=2;
base*=10;
}
cout<<"Binary equivalent:"<<binary;
return 0;
}
Output
Enter any number: 12
Binary equivalent: 1100