CodesJava

Easy learning with example program codes

CPP program to convert a decimal number into a binary number


Decimal System: A number system with base 10 i.e, numbers from 0-9 are used to represent a decimal number system.

Binary System: A number system with base 2 i.e, only binary numbers 0 and 1 are used to represent a binary number system.

Code:

#include <iostream.h>
using namespace std;
 
int main()
{  
int arr[20];
int num,i;    
 
cout << "Enter the number: ";    
cin >> num;  
int n= num;
 
for(i=0;num>0;i++)    
{    
arr[i] = num%2;    
num = num/2;    
}   
 
cout << "Binary Value of " << n << " is: ";
for(i=i-1; i>=0; i--)    
cout << arr[i];    
return 0;
}

Output

Enter the number: 15
Binary value of 15 is: 1111
Posted in CPP   
Sign Up/ Sign In
Ask a Question


Industrial Training

We offers Placement Oriented Training on Java, Spring, JSF, Hibernate, PHP, AngularJS, Angular 4, PLSQL, Oracle BI Publisher etc. We also provides Online training, please mail us at hr@codesjava.com.

Development

We also provides the Development services for Website Development , Java Development, PHP Development, Android App Development etc. You can contact us on hr@codesjava.com.

Copyright © 2018 CodesJava DMCA.com Protection Status SiteMap Reference: Java Wiki