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 pass by value in c?

597


In c programming typeing to occupy the variables in memory space. if not useing the variable the memory space is wasted.ok, how to avoid the situation..? (the variable is used & notused)

1634


What are different types of variables in c?

571


How can I make sure that my program is the only one accessing a file?

680


What does d mean?

587






I was asked to write a program in c which when executed displays how many no.of clients are connected to the server.

1907


What are the types of pointers?

603


How will you divide two numbers in a MACRO?

715


Where are c variables stored in memory?

600


What is volatile variable in c?

659


Write a program to know whether the input number is an armstrong number.

674


How do you define a string?

658


When reallocating memory if any other pointers point into the same piece of memory do you have to readjust these other pointers or do they get readjusted automatically?

809


Explain what is the advantage of a random access file?

666


What is the sizeof () a pointer?

550