how to convert binary to decimal and decimal to binary in C
lanaguage

Answers were Sorted based on User's Feedback



how to convert binary to decimal and decimal to binary in C lanaguage..

Answer / rahul

[decimal to binary]
#include<stdio.h>
#include<conio.h>
void main()
{
int dec,bin,a[100],i=0,r,j;
printf("enter the decimal number: ");
scanf("%d",&dec);
while(dec>0)
{
r=dec%2;
dec=dec/2;
a[i]=r;
i++;
}
printf("the equivalant binary numberis: ");
for(j=i-1;j>=0;j--)
printf("%d",a[j]);
getch()
}

Is This Answer Correct ?    72 Yes 32 No

how to convert binary to decimal and decimal to binary in C lanaguage..

Answer / saravana priya

#include <stdio.h>

void main()
{
int num, bnum, dec = 0, base = 1, rem ;

printf(“Enter a binary number(1s and 0s)\n”);
scanf(“%d”, &num); /*maximum five digits */

bnum = num;

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

printf(“The Binary number is = %d\n”, bnum);
printf(“Its decimal equivalent is =%d\n”, dec);

} /* End of main() */

Is This Answer Correct ?    25 Yes 9 No

how to convert binary to decimal and decimal to binary in C lanaguage..

Answer / fazlur rahaman naik

u can use bitwise operators and some logical thinking.

Is This Answer Correct ?    26 Yes 15 No

how to convert binary to decimal and decimal to binary in C lanaguage..

Answer / ruchi

#include<stdio.h>
#include<conio.h>
#include<math.h>
int main()
{
int n,r,s=0,i=0;
printf("\nEnter the decimal number ");
scanf("%d",&n);
while(n>0)
{
r=n%2;
n=n/2;
s=s+r*pow(10,i++);
}
printf("\nThe binary equivalent is ");
printf("%d",s);
getch();
}

Is This Answer Correct ?    27 Yes 17 No

how to convert binary to decimal and decimal to binary in C lanaguage..

Answer / sheela

#include<stdio.h>
#include<conio.h>
#include<math.h>
int main()
{
int n,r,s=0,i=0;
printf("\nEnter the binary number ");
scanf("%d",&n);
while(n>0)
{
r=n%10;
n=n/10;
s=s+r*pow(2,i++);
}
printf("\nThe binary equivalent is ");
printf("%d",s);
getch();
}

Is This Answer Correct ?    10 Yes 2 No

how to convert binary to decimal and decimal to binary in C lanaguage..

Answer / rahul

//it is to convert Binary to decimal;


#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
long int a[20],i,n,count=0,b[20],c[20],sum=0;
printf("ENter the number in binary form=\t");
scanf("%ld",&n); // Get a binary number
from the user
for (i=0;n>=1;i++)
{
a[i]=n%10;
n=n/10; // Loop To reverse the number And put
all reversed numbers in arry a[i]
count=count + 1; // count to count the number of times
this loop runs
}
for (i=0;i<=count-1;i++) // count -1 condition is used to
run the loop till the previous loop run
{
b[i]=pow(2,i); // This is to raise the power of 2 to no
of times previous loop runned.
}
for (i=0;i<=count-1;i++)
{
c[i]=a[i] * b[i]; // Multiply a[i] or reveresed binary
no with b[i] or increasing pow of 2 to count-1
sum=sum +c[i]; // it is to add the c[i] elements with
each other n put into sum variable.
}
printf("Decimal form =%ld",sum); // printing the sum to get
the decimal form
getch();
}
// Hope it solves your problem, ANy more assistance
honey.gupta13@yahoo.com

Is This Answer Correct ?    15 Yes 9 No

how to convert binary to decimal and decimal to binary in C lanaguage..

Answer / naveen bhatt

#include<stdio.h>
#include<conio.h>
void main()
{
int i,r,d,num;
for(i=1;i<=num;i++)
r=num%2;
num=d*num/2;
printf("\n the valueis=%d",r);
getch();
}

Is This Answer Correct ?    4 Yes 9 No

Post New Answer

More C Interview Questions

How to draw the flowchart for structure programs?

0 Answers  


How can I do peek and poke in c?

0 Answers  


write a program to find lcm and hcf of two numbers??

1 Answers  


code for concatination of 2 strings with out using library functions?

3 Answers  


#define MAX 3 main() { printf("MAX = %d \n",MAX ); #undef MAX #ifdef MAX printf("Vector Institute”); #endif

4 Answers   IBM, Vector,






How does pointer work in c?

0 Answers  


What is mean by data types in c?

0 Answers  


Why do we need a structure?

0 Answers  


what is pointer?

13 Answers   HCL, TCS,


Identify the operators that is not used with pointer a. && b. # c. * d. >>

2 Answers  


Write an algorithm for implementing insertion and deletion operations in a singly linked list using arrays ?

0 Answers   MNC,


main() { int a; a=++100; printf("%d",a); getch(); }

4 Answers  


Categories