Decimal To Binary
This program convert a decimal number into binary number.
"/" is used instead of "<" and ">".
#include/stdio.h/
#include/conio.h/
#include/alloc.h/
struct node
{
int data;
struct node *link;
};
void atbeg(struct node**,int);
void display(struct node*);
int count(struct node*);
void main()
{
int n,i;
struct node *p;
p=NULL;
clrscr();
printf("enter the decimal number:");
scanf("%d",&n);
while(n!=0)
{
i=n%2;
atbeg(&p,i);
n=n/2;
}
display(p);
printf("\nnumber of elements=%d",count(p));
getch();
}
void atbeg(struct node **q,int i)
{
struct node *temp;
temp=malloc(sizeof(struct node));
temp->data=i;
temp->link=*q;
*q=temp;
}
void display(struct node *q)
{
printf("\n");
while(q!=NULL)
{
printf("%d",q->data);
q=q->link;
}
}
int count(struct node *q)
{
int c=0;
while(q!=NULL)
{
q=q->link;
c++;
}
return c;
}
0 comments:
Post a Comment