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

Answer Posted / rahul

[decimal to binary]
#include<stdio.h>
#include<conio.h>
void main()
{
int dec,bin,a[100],i=0,r,j;
printf("enter the decimal number: ");
scanf("%d",&dec);
while(dec>0)
{
r=dec%2;
dec=dec/2;
a[i]=r;
i++;
}
printf("the equivalant binary numberis: ");
for(j=i-1;j>=0;j--)
printf("%d",a[j]);
getch()
}

Is This Answer Correct ?    72 Yes 32 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

How will you write a code for accessing the length of an array without assigning it to another variable?

622


How can you tell whether two strings are the same?

836


can any one tel me wt is the question pattern for NIC exam

1563


write a program to convert a expression in polish notation(postfix) to inline(normal) something like make 723+* (2+3) x 7 (not sure) just check out its mainly printing expression in postfix form to infix.

3509


Find MAXIMUM of three distinct integers using a single C statement

632






What is the use of function in c?

717


What are enumerated types?

659


given post order,in order construct the corresponding binary tree

2332


What is c language & why it is used?

588


Why is c called c not d or e?

619


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

1825


write a C program: To search a file any word which starts with ?a?. If the word following this ?a? starts with a vowel.Then replace this ?a? with ?a? with ?an?. redirect with the output onto an output file.The source file and destination file are specified by the user int the command line.

2459


Why do we need volatile in c?

750


using only #include and #include Write a program in C that will read an input from the user and print it back to the user if it is a palindrome. The string ends when it encounters a whitespace. The input string is at most 30 characters. Assume the string has no spaces and distinguish between and lowercase. So madam is a palindrome, but MadAm is not a palindrome. Use scanf and %s to read the string. Sample Test: Enter a string: madam madam is a palindrome. Enter a string: 09023 09023 is not a palindrome.

1319


What does 4d mean in c?

955