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 a lookup table in c?
What is the purpose of 'register' keyword in c language?
What is volatile variable how do you declare it?
I need previous papers of CSC.......plz help out by posting them.......
What is string function in c?
Can you write a programmer for FACTORIAL using recursion?
Explain the bubble sort algorithm.
What does node * mean?
Is register a keyword in c?
what is associativity explain what is the precidence for * and & , * and ++ how the folloing declaration work 1) *&p; 2) *p++;
What is a dynamic array in c?
What is structure and union in c?
Write a code on reverse string and its complexity.
Do you know what are the properties of union in c?
How can I trap or ignore keyboard interrupts like control-c?