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

Explain how can I convert a string to a number?

640


Differentiate between a for loop and a while loop? What are it uses?

663


Why main is not a keyword in c?

641


What's the best way of making my program efficient?

619


What is the scope of static variable in c?

523






What is a function simple definition?

608


What does emoji p mean?

593


how logic is used

1493


What is c programing language?

610


What is a function in c?

567


What is the difference between the expression “++a” and “a++”?

644


What is getch c?

845


What is the right type to use for boolean values in c? Is there a standard type?

557


What is the usage of the pointer in c?

598


What is header file in c?

597