How many times will the innermost loop execute in the below code?
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;
}
Show answerHide answer
Correct answer: (A) 6 times
Explanation
The outer loop runs 3 times (i = 0,1,2) and the inner loop runs 2 times for each, so the inner body executes 3 x 2 = 6 times.