how to convert | decimal number to binary number in c language
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
int a,i=0,n,bin=0,r;
clrscr();
printf("enter the decimal no \n");
scanf("%d",&n);
while(n != 0)
{
r=n%2;
// a=pow(10,i);
bin=bin+(pow(10,i)*r);
i++;
n=n/2;
}
printf("binary no.=%d \n",bin);
printf("enter the binary no \n");
scanf("%d",&n);
i=0;
bin=0;
while(n != 0)
{
r=n%10;
bin=bin+(pow(2,i)*r);
i++;
n=n/10;
}
printf("decimal no.=%d",bin);
getch();
}
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
int a,i=0,n,bin=0,r;
clrscr();
printf("enter the decimal no \n");
scanf("%d",&n);
while(n != 0)
{
r=n%2;
// a=pow(10,i);
bin=bin+(pow(10,i)*r);
i++;
n=n/2;
}
printf("binary no.=%d \n",bin);
printf("enter the binary no \n");
scanf("%d",&n);
i=0;
bin=0;
while(n != 0)
{
r=n%10;
bin=bin+(pow(2,i)*r);
i++;
n=n/10;
}
printf("decimal no.=%d",bin);
getch();
}
0 comments: