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

How can I convert integers to binary or hexadecimal?

2 Answers  


Write a Program to print this triangle: * ** * **** * ****** * ******** * ********** use two nested loops.

12 Answers   MIT, TCS,


what is the meaning of java that is (J A V A) full form of JAVA

71 Answers   AKS University, Bhel, BNL, BPO, HCL, Peacecon,


post new interiew question and aptitude test papers

1 Answers  


define function

4 Answers   Assurgent, Sonata,






Should I learn c before c++?

0 Answers  


write a c/c++ program that takes a 5 digit number and calculates 2 power that number and prints it?

4 Answers  


Write a C Program That Will Count The Number Of Even And Odd Integers In A Set using while loop

0 Answers   HP,


without using control structures and control structures find the max and min of given 2 nos

1 Answers   HCL,


Program to trim a given character from a string.

5 Answers   NetApp,


Why do we use namespace feature?

0 Answers  


main() { int i=0; while(+(+i--)!=0) i-=i++; printf("%d",i); }

4 Answers  


Categories