Decimal to Binary Conversion Using C language


//WAP to convert a decimal number to a binary number
#include<stdio.h>
void main()
{
int n,i=1,r,ten=1,bin=0;
printf("Enter a decimal number:");
scanf("%d",&n);
while(n>0)
{
r=n%2;
bin=bin+r*ten;
n/=2;
ten=ten*10;
}
printf("Your binary value is:%d",bin);
}


Binary to Decimal Conversion Using C language


//WAP to convert a binary number to decimal number.
#include
#include
void main()
{
int n,r,dec=0,i=0;
printf("Enter your binary number:");
scanf("%d",&n);
while(n>0)
{
r=n%10;
dec=dec+r*pow(2,i);
i++;
n=n/10;
}
printf("%d",dec);
}



0 Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.