Friday, 29 April 2016

C++ Program to Find the Binary Value of Decimal Numbers

In this program we will find the binary value of decimal numbers
           Code is given below

//CODE Starts 
#include<iostream>
#include <conio.h>
using namespace std;


int main()
{
int n,x,a, c, k;


cout<<"Enter an integer in decimal number system (0-9) : ";
cin>>x;
n=x;
cout<<"Binary Value OF Given Number Is: ";


for( a=1;n!=0;a++)
{
n=n/2;
}

a=a-2;

for (c = a; c >= 0; c--)
{
k = x >> c;
    if (k & 1)   
  {      
cout<<"1";     
 }    
else   
 {      
 cout<<"0";
}
          }

getch();
}
          //CODE Ends

OUTPUT:

Share:

0 comments:

Post a Comment