how to convert binary to decimal and decimal to binary in C
lanaguage
Answer Posted / saravana priya
#include <stdio.h>
void main()
{
int num, bnum, dec = 0, base = 1, rem ;
printf(“Enter a binary number(1s and 0s)\n”);
scanf(“%d”, &num); /*maximum five digits */
bnum = num;
while( num > 0)
{
rem = num % 10;
dec = dec + rem * base;
num = num / 10 ;
base = base * 2;
}
printf(“The Binary number is = %d\n”, bnum);
printf(“Its decimal equivalent is =%d\n”, dec);
} /* End of main() */
| Is This Answer Correct ? | 25 Yes | 9 No |
Post New Answer View All Answers
What is the difference between text files and binary files?
What are the advantages and disadvantages of a heap?
the number of measuring units from a arbitrary starting point in a record area or control block to some other point a) branching b) recording pointer c) none d) offset
What does s c mean in text?
what are the 10 different models of writing an addition program in C language?
How can I convert a number to a string?
How can I write functions that take a variable number of arguments?
Is it better to bitshift a value than to multiply by 2?
How can I display a percentage-done indication that updates itself in place, or show one of those twirling baton progress indicators?
I need a sort of an approximate strcmp routine?
Why we use stdio h in c?
Write a program to check prime number in c programming?
What is static memory allocation?
How can I get random integers in a certain range?
Explain what is the most efficient way to store flag values?