Question discussion

How many times will the innermost loop execute in the below code?

359232Medium DSSSB TGT Computer Science 0 replies 0 views
0
How many times will the innermost loop execute in the below code?
#include <stdio.h>
int main() {
    for(int i=0; i<3; i++)
    {
        for(int j=0; j<2; j++)
        {
            printf("%d ",i);
        }
    }
    return 0;
}
  • A6 times
  • B3 times
  • C5 times
  • D2 times
Correct answer: A

Explanation

The outer loop runs 3 times and the inner loop 2 times each, so the innermost loop executes 3 × 2 = 6 times.

Discussion 0

Nobody has replied yet. Start the discussion!