how to find binary of number?

Answer Posted / abhishek karnani

Here is a prgm to convert a decimal number to any base just
replace 2 by the base number of the desired number


#include<stdio.h>
#include<conio.h>
void main()
{
int d;
int i=0,n,j,b[100];
clrscr();
printf("\nEnter decimal number: ");
scanf("%d",&n);
while (n>0)
{
b[i]=n%2;
n=n/2;
i++;
}

printf("\nBinary is: ");

for (j=i-1;j>=0;j--)
{
printf("%d",b[j]);
}
getch();
}

Is This Answer Correct ?    4 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is the role of && operator in a program code?

656


What is the modulus operator?

822


if the area was hit by a virus and so the decrease in the population because of death was x/3 and the migration from other places increased a population by 2x then annually it had so many ppl. find our the population in the starting.

4644


Is it possible to have a function as a parameter in another function?

710


Explain with the aid of an example why arrays of structures don’t provide an efficient representation when it comes to adding and deleting records internal to the array.

2749






Do character constants represent numerical values?

946


Who is the main contributor in designing the c language after dennis ritchie?

649


What is sorting in c plus plus?

637


Explain what will the preprocessor do for a program?

690


Is main is a keyword in c?

712


Explain about C function prototype?

702


How do you do dynamic memory allocation in C applications?

725


A variable that is defined in a specified portion of a program but can be used throughout the program a) global variable b) local variable c) character d) none

830


How do you write a program which produces its own source code as output?

704


I have seen function declarations that look like this

690