Converting decimal to binary
Converting decimal into Binary
Language: C++
Author: Aamir Mustafa
E-Mail: aamir_mustafa2007@msn.com
Introduction:
This simple program will convert a decimal number into equivalent binary
Code:
#include
#include
void main(void)
{
int bi,i,k; //declaring variables of integer type//
cout<<"Enter decimal number="; //asking user to prompt//
cin>>bi; //taking input//
cout<<"Its Binary Equivalent is ="; //getting the out put//
for(i=1;i<=12;i++) //executing for loop for 12 times//
{
k=bi%2; //getting the remainder//
bi=bi/2; //dividing by 2
cout<
}
cout<
getche();
}
Alternative Method
#include
#include
int main()
{
int num;
int result[12];
int i=0;
cout<<"enter the decimal number ";
cin>>num;
while(i<=12)
{
result[i]=num%2;
num=num/2;
i++;
}
for(int j=0;j<=12;j++)
cout<<>
cout<<>
system("pause");
}