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 can LOCATE and INSERT elements in array using c++ programming languages.

0 Answers  


3. Program to find the Sum of give series. a. (1)+(1+2)+(1+2+3)+(1+2+3+4)+……………………………….. b. 1/1+1/9+1/25+1/49+……………...

0 Answers  


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  


what is the difference between int &r and int& r

3 Answers  


Write a function- oriented to convert the input dollar(s) into its equivalent peso. Assume that one dollar is equivalent to 51.60

1 Answers  






Given a table of the form: Product Sold on A 1/1/1980 B 1/1/1980 C 1/1/1980 A 1/1/1980 B 1/1/1980 C 2/1/1980 A 2/1/1980 There are 30 products and 10,000 records of such type. Also the month period during which sales happened is given to u. Write the program to display the result as: Product Month No. of copies A January 12 A February 15 A March 27 B January 54 B February 15 B March 10 C January 37

0 Answers  


write a c program, using for loop, that accepts and odds two numbers. The output must be the sum and the addens. This should be repeated 5 times while the first number is decremented by one and the second number is incremented by 1.

2 Answers   IBM, Infosys,


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  


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,


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  


Code for Two Classes for Doing Gzip in Memory?

0 Answers  


Teta-Omeg-Big-Oh Show that f(n) = n2 + 3n3 is ;(n3).

0 Answers   Qatar University,


Categories