Program to convert Decimal number into its Binary equivalent
#include<iostream>
#include<conio.h>
using namespace std;
int main()
{
int decimal_number = 0, binary_number = 0,
temp_number = 0, remainder = 0, counter = 1;
cout
<< "\n\n\t __ Program to convert Decimal number into
Binary number __";
cout
<< "\n\n\n Enter the Decimal Number - ";
cin
>> decimal_number;
temp_number
= decimal_number;
while(temp_number != 0)
{
remainder
= temp_number % 2;
temp_number
= temp_number / 2;
binary_number
= binary_number + remainder * counter;
counter
= counter * 10;
}
cout
<< "\n\n
Binary Conversion of Decimal Number " <<
decimal_number;
cout << " (BASE 10) is --
" << binary_number << "
(BASE 2)";
getch();
return 0;
}
Check out the link for the detailed steps of how to convert decimal number into binary number - Decimal to Binary Conversion
No comments:
Post a Comment