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

Write a program to generate prime factors of a given integer?

9 Answers   Microsoft,


Do pointers need to be initialized?

0 Answers  


When can you use a pointer with a function?

0 Answers  


Do you know the purpose of 'register' keyword?

0 Answers  


can any one please explain, how can i access hard disk(physical address)? it is possible by the use of far,near or huge pointer? if yes then please explain......

0 Answers  


Explain what would happen to x in this expression: x += 15; (assuming the value of x is 5)

0 Answers  


plz let me know how to become a telecom protocol tester. thank you.

0 Answers  


Can the “if” function be used in comparing strings?

0 Answers  


how to set Nth bit of variable by using MACRO

3 Answers   HCL,


Tell me when would you use a pointer to a function?

0 Answers  


what is dangling pointer?

1 Answers   LG Soft,


Write code for initializing one dimentional and two dimentional array in a C Program?

5 Answers   Deshaw, Edutech, GMD,


Categories