Consider the following C program:

#include <stdio.h>

int main(){
    int a = 6
    int b = 0;
    while(a < 10) {
        a = a / 12 + 1;
        a += b;
    }
    printf("%d", a);
    return 0;
}

Which one of the following statements is CORRECT?

A.

The program prints 9 as output

B.

The program prints 10 as output

C.

The program gets stuck in an infinite loop

D.

The program prints 6 as output

Solution:
  • Initially, a = 6 and b = 0.
  • In the first iteration of the loop, a is divided by 12, which results in 0 (since 6 / 12 = 0 in integer division), and then 1 is added to it. So, a becomes 1. Then b (which is 0) is added to a, so a remains 1.
  • Since a is still less than 10, the loop continues.
  • In the next iteration, a is less than 10 and will remain 1. Due to this, a will never be greater than 10 and the program will get stuck in an infinite loop.

The program will stuck in an infinite loop and will not print anything.

Option C is correct.