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 what are its uses in c programming?
Can a variable be both constant and volatile?
what is the c source code for the below output? 5555555555 4444 4444 333 333 22 22 1 1 22 22 333 333 4444 4444 5555555555
Write the program that calculates and prints the average of several integers. Assume that the last value read is sentinel 9999.
What is the use of a static variable in c?
Can you tell me how to check whether a linked list is circular?
What are pointers?
an expression contains relational operators, assignment operators, and arithmatic operstors. In the absence of parentheses, they will be evaluated in which of the following order a) assignment, relational, arithematic b) arithematic, relational, assignment c) relational, arithematic, assignment d) assignment, arithematic, relational
What is a struct c#?
What is difference between class and structure?
Explain what are the different file extensions involved when programming in c?
What is the benefit of using const for declaring constants?
Simplify the program segment if X = B then C ← true else C ← false
Why c is a procedural language?
can anyone please tell about the nested interrupts?