how to convert binary to decimal and decimal to binary in C
lanaguage

Answer Posted / ruchi

#include<stdio.h>
#include<conio.h>
#include<math.h>
int main()
{
int n,r,s=0,i=0;
printf("\nEnter the decimal number ");
scanf("%d",&n);
while(n>0)
{
r=n%2;
n=n/2;
s=s+r*pow(10,i++);
}
printf("\nThe binary equivalent is ");
printf("%d",s);
getch();
}

Is This Answer Correct ?    27 Yes 17 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

The file stdio.h, what does it contain?

665


define string ?

664


What is line in c preprocessor?

610


Explain how can you be sure that a program follows the ansi c standard?

856


What do the functions atoi(), itoa() and gcvt() do?

722






What is the advantage of an array over individual variables?

733


How do I get an accurate error status return from system on ms-dos?

643


How do you list files in a directory?

559


What are the 4 data types?

592


What is preprocessor with example?

578


Describe the modifier in c?

597


What is identifiers in c with examples?

675


What is clrscr ()?

633


Write the test cases for checking a variable having value in range -10.0 to +10.0?

1813


Explain how are portions of a program disabled in demo versions?

649