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

Why is c so powerful?

873


PLS U SENS ME INTERVIEW O. MY EMAIL ADD, SOFIYA.SINGH@GMAIL.COM

1931


What is union and structure in c?

834


Explain what header files do I need in order to define the standard library functions I use?

840


Explain can static variables be declared in a header file?

883


how do you programme Carrier Sense Multiple Access

1707


How can I delete a file?

809


What is a const pointer in c?

848


What are linked lists in c?

832


Explain #pragma statements.

794


How important is structure in life?

768


How can I do peek and poke in c?

831


What does it mean when a pointer is used in an if statement?

827


What happens if a header file is included twice?

771


What is the use of clrscr?

773