In this program we will find the binary value of decimal numbersCode 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";}
}
//CODE Ends
getch();
}
OUTPUT:
0 comments:
Post a Comment