A simple c and c++ program to convert a decimal number into binary number system.
C/C++ program to convert base ten number system into base two number system or 0’s and 1’s format.
Program is simple and it just convert simple integers decimal into binary. This will not work for floating values and negative values.
C Code
#include <stdio.h> #include <conio.h> using namespace std; void main() { int a=1,sum=0,x; printf("Enter a Decimel Number: "); scanf("%d", &x); int num=x; do { sum+=(x%2)*a; x=x/2; a=a*10; } while(x!=0); printf("Binary of %d is: %d",num ,sum); getche(); }
C++ Code
#include <iostream> using namespace std; int main() { int a=1,sum=0,x; cout << "Enter a Decimel Number: "; cin >> x; int num=x; do { sum+=(x%2)*a; x=x/2; a=a*10; } while(x!=0); cout << "Binary of " << num << " is: " << sum; }
Output:
Other Related Search Terms
- C++ program to convert base 10 number system in base 2 number system
- C program to convert base 10 number system in base 2 number system
- C++ program to convert decimal into binary.
- C program to convert decimal into binary