how to convert decimal to binary in c using while loop
without using array
Answers were Sorted based on User's Feedback
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 |
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 |
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 |
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 |
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 |
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 |
Answer / chiran ravani
sorry friends please ignore the previous answer.
| Is This Answer Correct ? | 0 Yes | 0 No |
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 |
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 |
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 |
I can not get my C++ program to work right. It is supposed to tell if a word is a palindrome or not, but it only tells thet the word is not a palindrome. And I can't fix it.
how to convert decimal to binary in c using while loop without using array
50 Answers Apple, Aptech, Arwen Tech, BCS, C2D Software, CEC,
I am using Qt 5.6 during compilation it stops and gives error about Qmake The process "C:QtQt5.6.35.6.3msvc2015_64inqmake.exe" crashed. Error while building/deploying project untitled1 (kit: Desktop Qt 5.6.3 MSVC2015 64bit) When executing step "qmake"
what is syntax error?
class test { int a; public: test(int b):a(b){} void show(){ cout<<a; } }; void main() { test t1; test t2(5); t1.show(); t2.show(); } }
full c programming error question based problem
How to upgrade LOOP environment, I just mean, how can i make loop statement editable ? I just try some program using loop statement and checking it in multiple compilers. Every compiler showing different output, what's the wrong ? is it a compiler based problem, or loop based problem, tell me why ? and what will be the debugging process, for this kind of problem ?
I'm having trouble with coming up with the correct code. Do I need to put a loop? Please let me know if I'm on the right track and what areas I need to correct. I still don't have a good grasp on this programming stuff. Thanks =) The assignment was to write a program using string functions that accepts a coded value of an item and displays its equivalent tag price. The base of the keys: 0 1 2 3 4 5 6 7 8 9 X C O M P U T E R S Sample I/O Dialogue: Enter coded value: TR.XX Tag Price : 68.00
How to convert hexadecimal to binary using c language..
1 Answers Bajaj, GAIL, Satyam, Zenqa,
What are the different types of errors in C and when they occur?
Why are memory errors hard to debug?
void main() { int i=1; printf("%d%d%d",i,++i,i++); } Cau u say the output....?