int main()
{
int i, j, sum = 0;
for(i=0;i<3;i++)
{
for(j=0;j<4;j++)
{
if(j > 2) break;
sum++;
}
}
}
What is value of sum, explain.
Ans: sum= 9
Here the inner loop executes 4 times.
But if 'j' value is greater than 2 then the loop will break.
so, for j=0,1,2 the sum value is incremented.
so, sum is incremented 3 times due to inner loop.
and the outer loop executes 3 times.
so, 3*3=9 times.
so, if increment sum value 9 times from sum=0
the sum value becomes 9.
so, the sum value is 9 after execution.
Get Answers For Free
Most questions answered within 1 hours.