Deitel & Deitel, C How to Program 3rd Edition, Exercise 3.36



#include <stdio.h>

int main() {

int binary, b = 1, a, j = 0, result = 0, i = 0, remain;
printf("Enter a binary: ");
scanf("%d", &binary);
remain = binary;
while (remain >= 1) {
a = remain % 10;
remain /= 10;
while (j < i) {
b *= 2;
j++;
}
result += a * b;
i++;
}
printf("%d\n", result);

return 0;
}

Comments

Popular posts from this blog

Deitel & Deitel, C How to Program 6th Edition, Exercise 6.23 (Turtle Graphics)

Deitel & Deitel, C How to Program 6th Edition, Exercise 6.22 (Total Sales)

Deitel & Deitel, C How to Program 6th Edition, Exercise 5.47 (Craps Game Modification)