//Decimal to Binary
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
long n,dn,r,base=1,bin=0;
cout<<"Enter any decimal value\n";
cin>>n;
dn=n;
while(n>0)
{
r=n%2;
bin=bin+r*base;
n=n/2;
base=base*10;
}
cout<<"Enter Number is:"<<dn<<endl;
cout<<"Binary value is:"<<bin<<endl;
getch();
}
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
long n,dn,r,base=1,bin=0;
cout<<"Enter any decimal value\n";
cin>>n;
dn=n;
while(n>0)
{
r=n%2;
bin=bin+r*base;
n=n/2;
base=base*10;
}
cout<<"Enter Number is:"<<dn<<endl;
cout<<"Binary value is:"<<bin<<endl;
getch();
}
No comments:
Post a Comment
Note: only a member of this blog may post a comment.