Convert Decimal to binary using C
Hey guys once again welcome to the Decoders blog, I hope you all are doing well and today I'm present with another logic but this time we will convert decimal to binary number using C programm........
#include<stdio.h>
#include<string.h>
#include<math.h>
int main()
{
int num,bin=0,place=1,rem;
printf("Enter the number\n");
scanf("%d",&num);
while(num>0)
{
rem =num%2; //Returns the reminder by dividing the number with 2
num =num/2; //Returns the integer value after dividing the number by 2
bin += place*rem; //Store the binary value
place *= 10;
}
printf("The binary number is %d",bin);
}
Comments
Post a Comment