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
formula to convert 2500mmh2o into m3/hr
Explain how do you print an address?
What is multidimensional arrays
When should you use a type cast?
Can the curly brackets { } be used to enclose a single line of code?
Create a registration form application by taking the details like username, address, phone number, email with password and confirm password (should be same as password).Ensure that the password is of 8 characters with only numbers and alphabets. Take such details for 3 users and display the details. While taking input password must appear as “****”.
Why do we need volatile in c?
Explain what are the advantages and disadvantages of a heap?
Explain the difference between malloc() and calloc() function?
How can I make it pause before closing the program output window?
What is the collection of communication lines and routers called?
What is use of pointer?
What is a program flowchart and how does it help in writing a program?
Explain what are header files and explain what are its uses in c programming?
What is the difference between int main and void main?