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

void main() { int i=5,y=3,z=2,ans; clrscr(); printf("%d",++i + --z + i++ + --i * ++y); i=5,y=3,z=2; ans=++i + --z + i++ + --i * ++y; printf("\n%d",ans); getch(); } Its output is 37 and 31.... Please explain me why its different How it works.....

2 Answers  


Find the error (2.5*2=5) (a) X=y=z=0.5,2.0-5.75 (b) s=15;

3 Answers  


Write a C program to enter 10 integer numbers through one variable and count how many of them are even using while loop ?

2 Answers  


char* f() return "hello:"; void main() {char *str=f(); }

1 Answers  


UINT i,j; i = j = 0; i = ( i++ > ++j ) ? i++ : i--; explain pls....

5 Answers  






What is the code for following o/p * * * * * * * * * * * * * * * *

1 Answers  


What is the out put of this programme? int a,b,c,d; printf("Enter Number!\n"); scanf("%d",&a); while(a=!0) { printf("Enter numbers/n"); scanf("%d%d%d",&b,&c,&d); a=a*b*c*d; } printf("thanks!"); getche(); Entering numbers are a=1,b=2,c=3,d=4 b=3,c=4,d=-5 b=3,c=4,d=0

5 Answers   TCS,


A sample program using data structure? what is file handling?

0 Answers   TCS,


#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,


quoroum of computer languages?

0 Answers   Infosys,


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  


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

19 Answers  


Categories