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 Linker and Loader

5 Answers  


HOW TO SOLVE A NUMERICAL OF LRU IN OS ??????

0 Answers  


When c language was developed?

0 Answers  


what is a function pointer and how all to declare ,define and implement it ???

4 Answers   Honeywell,


list the no of files created when c source file is compiled

9 Answers   TCS,


What is the relation between # and include<stdio.h>

5 Answers   HCL,


What should be keep precautions while using the recursion method?

1 Answers  


Where static variables are stored in c?

0 Answers  


What is the equivalent code of the following statement in WHILE LOOP format?

0 Answers  


how to convert an char array to decimal array

4 Answers  


what is associativity explain what is the precidence for * and & , * and ++ how the folloing declaration work 1) *&p; 2) *p++;

0 Answers   L&T,


What is pass by value in c?

0 Answers  


Categories