@Arjunsir the value of outer loop(i) ranges from 1 to n and depending on the value of i we calculate the number of turn (j) which the inner loops execute.

here i and j are related to the time complexity as the summation of total number of times the inner loops runs for each iteration of the outer loop is our desired time complexity .Depending on that result we can comment on the asymptotic notation.

yes, now fine. Basically we are counting the number of times printf is happening as that statement is the most executed one. ((j <= p) conditional will actually execute one extra time)

The steps given are essential if the question asks for the exact term. For asymptotic time complexity you might be able to skip a few steps.