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
Explain the difference between call by value and call by reference in c language?
Who invented b language?
Why we use void main in c?
In c programming typeing to occupy the variables in memory space. if not useing the variable the memory space is wasted.ok, how to avoid the situation..? (the variable is used & notused)
What could possibly be the problem if a valid function name such as tolower() is being reported by the C compiler as undefined?
What should malloc() do?
What does it mean when the linker says that _end is undefined?
why we wont use '&' sing in aceesing the string using scanf
which is conditional construct a) if statement b) switch statement c) while/for d) goto
What is the difference between ++a and a++?
why use "return" statement a) on executing the return statement it immediately transfers the control back to the calling program b) it returns the value present in the parentheses return, to the calling program c) a & b d) none of the above
What standard functions are available to manipulate strings?
Why is python slower than c?
What are linked lists in c?
What is a pointer in c plus plus?