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

Explain what math functions are available for integers? For floating point?

0 Answers  


Explain what is wrong with this program statement? Void = 10;

0 Answers  


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

0 Answers  


print ur name without using any semicolon in c/c++....

21 Answers   Bosch, TCS, Wipro,


char S; char S[6]= " HELLO"; printf("%s ",S[6]); output of the above program ? (0, ASCII 0, I,unpredictable)

7 Answers   Mascot,






How a string is stored in c?

0 Answers  


Why isn't any of this standardized in c? Any real program has to do some of these things.

0 Answers  


how does the for loop work actually..suppose for the following program how it ll work plz explain to me for(i=5;i>=0;i--) prinf(i--);

19 Answers   RMSI,


how to generate sparse matrix in c

3 Answers  


What does the error message "DGROUP exceeds 64K" mean?

0 Answers   Celstream,


What is the purpose of sprintf?

0 Answers  


write a c program to find the sum of five entered numbers using an array named number

0 Answers   TATA,


Categories