A Binary no. is given, we hav to find it's decimal
equivalent.

Answers were Sorted based on User's Feedback



A Binary no. is given, we hav to find it's decimal equivalent...

Answer / jaydeep patel

#include <conio.h>
#include<stdio.h>
#include<iostream.h>
#include<math.h>
void main(void)
{
clrscr();
int binary,len,dec=0;
cout<<"Enter Binary No:: ";
cin>>binary;
for(int i=0;;i++)
{ if(binary==0)
break;
else
{
int temp=binary%10;
dec=dec+(pow(2,i)*temp);
binary=binary/10;
}
}
cout<<endl<<"Decimal No is:: "<<dec;
getch();
}

Is This Answer Correct ?    1 Yes 0 No

A Binary no. is given, we hav to find it's decimal equivalent...

Answer / bunker

include<stdio.h>
include<conio.h>
void main()
{
int n,x,a,i;
printf("ENTER THE DECIMAL NO");
scanf("%d'&n);
for(i=2;i<=n;i++)
x=n%2;
a=x/2;
printf("binary %d",a);
getch();
}

Is This Answer Correct ?    6 Yes 24 No

Post New Answer

More C++ Code Interview Questions

Write a program that takes a 3 digit number n and finds out whether the number 2^n + 1 is prime, or if it is not prime find out its factors.

5 Answers   ADP, Amazon, HCL, IBM, Infosys, Satyam, TCS, Vimukti Technologies,


write a program that reverses the input number of n.Formulate an equation to come up with the answer.

0 Answers   Satyam,


Write code for the multiplication of COMPLEX numbers?

0 Answers   IBM,


using friend function find the maximum number from given two numbers from two different classes.write all necessary functions and constructor for the classes.

1 Answers   TCS,


main(){int a=5,b 10,c=2, d;a=b c;d=++a=(--c)*2; printf("%d%d%d%d,a,b,c,d; return o;}

1 Answers  






Find the maximum product of three numbers in an array? Eg. 9,5,1,2,3 Max product= 9*5*3= 135 The array can hav negative numbers also..

7 Answers   CTS,


Write a program that print in screen a tree with its height taken from user by entering number of 4 digits and find the odd numbers then calculate the sum of odd numbers so he get the height of tree?

0 Answers  


Write a program using one dimensional array that searches a number and display the number of times it occurs on the list of 12 input values. Sample input/output dialogue: Enter 12 values: 13 15 20 13 30 35 40 16 18 20 18 20 Enter number to search: 20 Occurences: 3

2 Answers  


write a function – oriented program that calculates the sum of the squares from 1 to n. thus, if the input is 3, the output is 14

3 Answers  


How to swap two ASCII numbers?

0 Answers  


write a function -oriented program that generates the Fibonacci, the current numbers of n(as input) and display them (series). In Fibonacci, the current third number is the sum of the previous number.

3 Answers  


write a program that accepts a number and outputs its equivalent in words. take note that the maximum input is 3000

1 Answers   Alvin,


Categories