#include<iostream>
using namespace std;
struct decimal
{
int num;
decimal *next;
}*head;
void convert( int num)
{ decimal * d= new decimal ;
while(num!=0)
{
decimal * d= new decimal ;
d->next=NULL;
if(head==NULL)
{
d->num=num%2;
head=d;
num/=2;
}
else {
d->num=num%2;
d->next=head;
head=d;
num/=2;
}
}}
void display()
{
decimal * temp;
temp=head;
while(temp!=NULL)
{
cout<<temp->num;
temp=temp->next;
}
}
int main()
{ head =NULL;
int num;
cout<<"Enter the number please "<<endl;
cin>>num;
cout<<"The decimal in binary =";
convert(num);
display();
}
No comments:
Post a Comment