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
Why is it important to memset a variable, immediately after allocating memory to it ?
Why do we use static in c?
What is #include cctype?
Differentiate between a for loop and a while loop? What are it uses?
Are there any problems with performing mathematical operations on different variable types?
how to construct a simulator keeping the logical boolean gates in c
what is the c source code for the below output? 10 10 10 10 10 10 10 10 10 10 9 9 7 6 6 6 6 6 6 9 7 5 9 7 3 2 2 5 9 7 3 1 5 9 7 3 5 9 7 4 4 4 4 5 9 7 8 8 8 8 8 8 8 8 9
What is substring in c?
What is file in c preprocessor?
Explain what is wrong with this statement? Myname = ?robin?;
Did c have any year 2000 problems?
Should a function contain a return statement if it does not return a value?
Define the scope of static variables.
What does struct node * mean?
difference between native and cross compilers