how to convert decimal to binary in c using while loop
without using array

Answers were Sorted based on User's Feedback



how to convert decimal to binary in c using while loop without using array..

Answer / tushar srivastava

Hello Friends,
I am having a question here....
If you can save a binary number in at maximum four bytes,
then why are you wasting 16 bytes for the same. This method
is not recommended by me lest you need to send data to some
output port. And even the previous method ie my method can
directly be used to transfer data though serial or parallel
port if needed. Ponder over it......

Is This Answer Correct ?    2 Yes 2 No

how to convert decimal to binary in c using while loop without using array..

Answer / praveenkumar

#include<stdio.h>
#include<conio.h>
void main()
{
long int dec,k=0,i=0,j=0,n,remainder,result[100];
printf("\n Enter any Value : ");
scanf("%ld",&dec);
while(dec>0)
{
remainder=dec%2;
result[k]=remainder;
k++;
dec=dec/2;
if(remainder==0)
{
i++;
}
else
{
j++;
}
}
printf("\n Binary : ");
for(n=k-1;n>=0;n--)
printf("%d",result[n]);
printf("\n 0's : %ld",i);
printf("\n 1's : %ld",j);
printf("\n Total Digits : %d",k);
getch();
}

Is This Answer Correct ?    3 Yes 3 No

how to convert decimal to binary in c using while loop without using array..

Answer / suresh

#include<stdio.h>
#include<conio.h>
void main()
{
int i,n;
clrscr();
scanf("%d",&n);
i=0;
while(i<=15)
{
printf("%d",(n<<i)&(1<<15)?1:0);
i++;
}
}

Is This Answer Correct ?    0 Yes 0 No

how to convert decimal to binary in c using while loop without using array..

Answer / bhagyashree

Q.How to convert to binary to decimal in c++ using array.

#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int i,n,j[8]={1,2,4,8,16,32},k=0;
int num[10],num1[10],s=0;
cout<<"Enter total num of digit:";
cin>>n;
for(i=0;i<n;i++)
{
cout<<"\nEnter "<<i+1<<" position";
cin>>num[i];
}
for(i=n-1;i>=0;i--)
{
num1[i]=num[i]*j[k];
s=s+num1[i];
k++;
}
cout<<"s="<<s;
getch();
}

Is This Answer Correct ?    0 Yes 0 No

how to convert decimal to binary in c using while loop without using array..

Answer / deva

#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
long int bn,temp;
int dn=0,e=0,digit;
clrscr();
printf("Enter binary number in form of 0 and 1 : ");
scanf("%ld",&bn);
temp=bn;
while(bn!=0)
{
digit= bn%10;
dn+=digit*pow(2,e);
e++;
bn/=10;}
printf("Binary number = %ld \n",temp);
printf("Decimal number= %d \n",dn);
getch();}

Is This Answer Correct ?    0 Yes 0 No

how to convert decimal to binary in c using while loop without using array..

Answer / chiran ravani

#include<stdio.h>
int main(void) {
int n,i=7,bin;
printf("Enter a decimal no:");
scanf("%d",&n);
while(i>=0) {
bin=n>>i;
if(bin&1)
printf("1");
else
printf("0");
i--;
}
}

Is This Answer Correct ?    0 Yes 0 No

how to convert decimal to binary in c using while loop without using array..

Answer / chiran ravani

sorry friends please ignore the previous answer.

Is This Answer Correct ?    0 Yes 0 No

how to convert decimal to binary in c using while loop without using array..

Answer / zahid

Any body help me to write a program to convert decimal to binary without using loop

Is This Answer Correct ?    0 Yes 0 No

how to convert decimal to binary in c using while loop without using array..

Answer / govind kumar

#include<conio.h>
#include<stdio.h>
void main()
{
int n,b=0,d=1,r,i=1;
printf("enter any binary no");
scanf("%d",&b);
while(n>0)
{
r=n%2;
b=b+r*d;
d=d*10;
n=n/2;
}
printf("the binary no is=%d",b);
}
getch;
}

Is This Answer Correct ?    0 Yes 0 No

how to convert decimal to binary in c using while loop without using array..

Answer / purva

#include<stdio.h>
#include<conio.h>
void main()
{
int n,i=1,a,d=0,b=0,c;
clrscr();
printf("enter decimal no.");
scanf("%d",&n);
while(n!=0)
{
a=n%2;
n=n/2;
d=d*10+a;
i++;
}
printf("d=%d",d);
while(d!=0)
{
c=d%10;
d=d/10;
b=b*10+c;
i++;
}
printf("\n binary equivalent is=%d",b);
getch();
}

Is This Answer Correct ?    0 Yes 1 No

Post New Answer

More C C++ Errors Interview Questions

void main() { int i=5,y=3,z=2,ans; clrscr(); printf("%d",++i + --z + i++ + --i * ++y); i=5,y=3,z=2; ans=++i + --z + i++ + --i * ++y; printf("\n%d",ans); getch(); } Its output is 37 and 31.... Please explain me why its different How it works.....

2 Answers  


How to create a program that lists the capital country when told what the original country is? (Terribly sorry, I'm a novice programmer and would appreciate any help ;). Cheers, Alexxis

0 Answers  


what is meant by linking error? how can i solve it? if there is a linking error " unable to open file 'cos.obj'? then what should i do?

1 Answers  


Given an int variable n that has already been declared and initialized to a positive value, and another int variable j that has already been declared, use a do...while loop to print a single line consisting of n asterisks. Thus if n contains 5, five asterisks will be printed. Use no variables other than n and j .

2 Answers  


#include<stdio.h> void main() { int i=1; printf("%d%d%d",i++,++i,i); }

19 Answers  






How to create a program that lists countries capitals when country is entered? (Terribly sorry, I'm a complete novist to coding with C, am looking for inspiration and general tips on how to code and create this program.)

0 Answers  


void main() { int i=1; printf("%d%d%d",i,++i,i++); } Cau u say the output....?

24 Answers   HCL,


Write a program to accept two strings of Odd lengths. Then take all odd characters from one string and even characters from the other and concatenate and produce a string.

1 Answers  


Assume that the int variables i and j have been declared, and that n has been declared and initialized. Write code that causes a "triangle" of asterisks of size n to be output to the screen. Specifically, n lines should be printed out, the first consisting of a single asterisk, the second consisting of two asterisks, the third consistings of three, etc. The last line should consist of n asterisks. Thus, for example, if n has value 3, the output of your code should be * ** *** You should not output any space characters. Hint: Use a for loop nested inside another for loop.

2 Answers   HCL,


void main() { int i=5; printf("%d",i+++++i); }

14 Answers   HCL,


what is meant for variable not found?

3 Answers  


how tally is useful?

2 Answers  


Categories