Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...


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 / casona the hunter

/* To Convert Using While Loop/*

#include <stdio.h>
#include<conio.h>

int main(void)
{
int Bin, Dec,Octal,Hexa,ans;
int rem[10],x=0;
char ch;
clrscr();



printf("B- - -Decimal-B\n\n");
printf("O- - -Decimal-O\n\n");
printf("H- - -Decimal-H\n\n");
printf("E- - -Exit\n\n");
printf("Choice:");
scanf("%c",& ch);
switch (ch)
{
case 'b': clrscr();
printf("Enter Decimal.:");
scanf("%d",& Dec);
while(Dec!=0)
{
rem[x] = Dec%2;
Dec = Dec/2;
x++;
}
x = x-1;

while (x>=0)
{
printf("%i",rem[x]);
x--;
}
}
getch();
return 0;
}

Is This Answer Correct ?    21 Yes 33 No

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

Answer / vimal vijayakumar

A simple code for u....

#include<stdio.h>
void main()
{
int n,b;
printf("Enter a no");
scanf("%d",&n);
while(n>0)
{
b=n%2;
if(b==1)
printf("0");
else
printf("1");
n=n/2;
}
getch();
}

send ur feed back to --- vimal9446706153@gmail.com

Is This Answer Correct ?    18 Yes 30 No

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

Answer / kk

//in c++
#include<iostream.h>
#include<conio.h>
void conv(int n)
{
int a[100],i;
for(i=0;n!=0;i++)
{
a[i]=n%2;
n=n/2;
}
cout<<"the binary is";
for(i-=1;i>=0;i--)
{
cout<<a[i];
}
}
void main()
{
clrscr();
int n;
cout<<"enter the no:";
cin>>n;
conv(n);
getch();
}

Is This Answer Correct ?    2 Yes 17 No

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

Answer / nick

/* convert a decimal number to binary */
int dectobin(int dec)
{
int bin=0, i=1;
while(dec!=0)
{
bin+=(dec%2)*i;
dec=dec/2;
i*=10;
}
return bin;
}

Is This Answer Correct ?    24 Yes 47 No

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

Answer / sam

all these answers crap

when you
b = b+rem*i
b is filled with int number
and adds the next one to it in the loop
so it wont be as b= 10011001
it will be b= the number i have intered
you idiots ....

Is This Answer Correct ?    29 Yes 56 No

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

Answer / darhakz

#include<stdio.h>
#include<math.h>
#include<string.h>

int bin2dec(int decimal);

int main(void)
{
int num;

printf("The decimal equilavent is: %d", bin2dec(decimal));

getchar();
getchar();
return 0;
}

int bin2dec(int decimal)
{
int num[10];
int i;
int bin;
int arr1[10];
int arr2[10] = {512,256,128,64,32,16,8,4,2,1};

printf("Enter a binary(0's and 1's) number: ");
scanf("%d", &arr1);

This is qheere I get confused.
for (i = 0; i < arr1; i++)
{
if (arr1[i] == 1)
num[i] = arr1[i];
arr2[i]= num[i]
decimal = arr2[i];
}

return decimal;
}

Is This Answer Correct ?    15 Yes 46 No

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

Answer / ritcanz

Void main()
{
int dec,i=1,rem,res=0;
Printf("Enter the Value %d",&dec);
while(dec!=0)
{
rem=dec%2;
dec=dec/2;
res=res+(i * 1);
i=i*10;

}
printf("The Binary value is %d",res);
}

Is This Answer Correct ?    15 Yes 48 No

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

Answer / sachin

#include<stdio.h>

int main()
{
int n, rem, num, i=1;

printf("enter no\n");
scanf("%d", &n);

while(n>0 )
{
rem = n % 2;
n = n/2;
num = (rem * i)+num;
i = i * 10;
}

printf("binary no: %d", num);
}

Is This Answer Correct ?    57 Yes 93 No

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

Answer / sujeeshkrishnan

main()
{
int dec,rem,ans=0;
printf("Enter the number\n");
scanf("%d",&dec);
while(dec>=2)
{
rem=dec%2;
dec=dec/2;
if(rem==0)
ans=ans*10;
else
ans=(ans*10)+1;
}
printf("The binary number is");
while(ans>0)
{
rem=ans%10;
ans=ans/10;
printf("%d",rem);
}
getch();
return 0;
}

Is This Answer Correct ?    74 Yes 163 No

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

Answer / sudha

Void main()
{
int dec,i=1,rem,res=0;
Printf("Enter the Value %d",&dec);
while(dec!=0)
{
rem=dec%2;
dec=dec/2;
res=res+(i * 1);
i=i*10;

}
printf("The Binary value is %d",res);
}

Is This Answer Correct ?    154 Yes 396 No

Post New Answer

More C C++ Errors Interview Questions

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.

1 Answers  


What are the different types of errors in C and when they occur?

4 Answers  


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(); } }

1 Answers  


Given that two int variables, total and amount, have been declared, write a loop that reads integers into amount and adds all the non-negative values into total. The loop terminates when a value less than 0 is read into amount. Don't forget to initialize total to 0. Instructor's notes: This problem requires either a while or a do-while loop.

3 Answers  


what is run time error?

7 Answers  


write the value of x and y after execution of the statements: int x=19,y; y=x++ + ++x; x++; y++;

0 Answers  


what is the error in the following code: main() { int i=400,j; j=(i*i)/i; }

4 Answers  


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  


#include<>stdio.h> #include<>conio.h> { printf("hello"); void main() getch(); } what the out put of this program and why ......plz clear my answer

10 Answers   Wipro,


what is exceptions?

5 Answers   HCL, Wipro,


WHAT WILL BE THE OUTPUT OF THE FOLLOWING QUESTION void main() { int x=4,y=3,z; z=x-- -y; printf("%d%d%d",x,y,z); }

25 Answers   HCL,


I'm having trouble with coming up with the correct code. Thank You!! The assignment was to write a program using string functions that accepts a price of an item and displays its coded value. The base of the keys: X C O M P U T E R S 0 1 2 3 4 5 6 7 8 9 Sample I/O Dialogue: Enter Price: 489.50 Coded Value: PRS.UX

0 Answers  


Categories