← Quiz: Number Programs in C: all 10 questions
Quiz: Number Programs in C · Question 9 of 10
What does this print? (code)
What does this print?
#include <stdio.h>
int main(void) {
int n = 10, bits[32], k = 0;
while (n > 0) { bits[k++] = n % 2; n /= 2; }
for (int i = 0; i < k; i++) printf("%d", bits[i]);
printf("\n");
return 0;
}
- A.1010
- B.0101
- C.10
- D.1100
Answer & explanation
Correct answer: 0101
The remainders come out as 0, 1, 0, 1; printing them in that order gives the binary of 10 reversed.
Can you get the rest right without peeking?
Take the timed Quiz: Number Programs in C quiz free. Pass it to earn XP and count towards your certificate.
Start the quiz →