how to find binary of number?

Answers were Sorted based on User's Feedback



how to find binary of number?..

Answer / 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

how to find binary of number?..

Answer / kamalb008

#include<stdio.h>
main()
{
int a,i,b,n;/*i have taken arbitary base u can enter the
base what ever u need*/
printf("enter the number and the base u want to conv resp");
scanf("%d%d",&a,&n);
i=1;
while(i<=20)
{
if(a<n)
break;
b=a%n;
a=a/n;
printf("\nLSB%d of the converted number is %d",i,b);
i++;
}
printf("\nMSB of the conv is %d",a);
}

Is This Answer Correct ?    1 Yes 1 No

Post New Answer

More C Interview Questions

The % symbol has a special use in a printf statement. How would you place this character as part of the output on the screen?

0 Answers  


What is the difference between the = symbol and == symbol?

0 Answers  


Why #include is used in c language?

0 Answers  


from which concept of 'c', the static member function of 'c++' has came?

1 Answers   Bosch,


write an algorithm to display a square matrix.

0 Answers  






ratio,age,persentage

0 Answers  


The differences between Windows XP and Windows Visa

8 Answers   HCL,


Is that possible to add pointers to each other?

0 Answers  


Explain what does the characters 'r' and 'w' mean when writing programs that will make use of files?

0 Answers  


How can I implement sets or arrays of bits?

0 Answers  


Is c is a procedural language?

0 Answers  


In c programming language, how many parameters can be passed to a function ?

0 Answers  


Categories