Give an advice about How many lines will be appeared in the following part of the code ?
for(i = 0; i < 5; i = i + 1)
for(j = 0; j < i; j = j + 1)
printf("%d %d\n", i, j);
I think is 5
So what do you think will be the results (How many lines) ?
Think about it, break it up into little steps.
i = 0 and j = 0 so j isn't less than i - therefore nothing gets prinited.
i now equals i + 1
i = 1 and j = 0 so j is now less than i - therefore i(1) is printed and j(0) is printed.
j now equals j + 1
The conidition j < i is checked and comes back false so we return to the outer loop.
The condidition i < 5 is still true so i is now equal to i(1) + 1
J is now reinitialized to 0 and the condition is checked which comes back true.
i = 2 and j = 0 so j is less than i - therefore i(2) is printed and j(0) is printed
j is incremented and and the condition is checked again which returns true as i = 2 and j = 1
i(2) and j(1) is therefore printed
and so on....
Why not compile it to view the output?
being able to read and understand code without compiling it is an important skill to learn.