Decimal to Binary conversion in C|Learnerspage

0
52
Decimal to Binary number conversion in C

#include <stdio.h>
#include <conio.h>
long DecimalToBinary(int decimalnum)
{
long binarynum = 0;
int r, temp = 1;

while (decimalnum!=0)
{
r = decimalnum%2;
decimalnum = decimalnum / 2;
binarynum = binarynum + r*temp;
temp = temp * 10;
}
return binarynum;
}
void main()
{
clrascr();
int num;
printf(“Enter a Decimal Number: “);
scanf(“%d”, &num);
printf(“Equivalent Binary Number is: %ld”, DecimalToBinary(num));
getch();
}

LEAVE A REPLY

Please enter your comment!
Please enter your name here