How to develop a program using C language to convert 8-bit
binary values to decimals. TQ



How to develop a program using C language to convert 8-bit binary values to decimals. TQ..

Answer / bashar khawaldeh

int arr[8];
int sum = 0;
int n = sizeof(arr) / sizeof(arr[0]);//24/4=6
for (int i = 0; i < n; i++) {
cout << "enter binary number
" << "index " << i << ":";
cin >> arr[i];
}

for (int i = 0; i < n; i++) {

if (arr[i] == 1) {
sum += pow(2,i);
}
}
cout << sum << endl;

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More C C++ Errors Interview Questions

#include<stdio.h> void main() { int i=1; printf("%d%d%d",i++,++i,i); }

19 Answers  


Write down the difference between c. Loop and goto statement d. (!0) and (!1) e. (1= =! 1) and (1!=1) f. NULL and !NULL

0 Answers  


what is run time error?

7 Answers  


what is meant by linking error? how can i solve it? if there is a linking error " unable to open file 'cos.obj'? then what should i do?

1 Answers  


what are the techniques for reducing the fragility of a memory bug?

1 Answers  


full c programming error question based problem

3 Answers   HCL, TCS,


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

4 Answers  


what is syntax error?

3 Answers  


void main() { int i=1; printf("%d%d%d",i,++i,i++); } Cau u say the output....?

24 Answers   HCL,


Given an int variable n that has been initialized to a positive value and, in addition, int variables k and total that have already been declared, use a do...while loop to compute the sum of the cubes of the first n whole numbers, and store this value in total . Thus if n equals 4, your code should put 1*1*1 + 2*2*2 + 3*3*3 + 4*4*4 into total . Use no variables other than n , k , and total .

3 Answers  


void main() { int i=7; printf("N= %*d",i,i); }

6 Answers   HCL,


Using string functions write a program that will accept the name of the capital as input value and will display the corresponding country. ------------------------ Capitals Countries ------------------------ Capitals Countries Ottawa Canada Moscow Russia Rome Italy I can't not get it to run properly

1 Answers   AMA,


Categories