Why it is not printing the answer

It is going in infinite loop, you are making i 0 in inner loop, then you are incrementing it.