🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← 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;
}
  1. A.1010
  2. B.0101
  3. C.10
  4. 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 →