Square root of imperfect square using for loop

How can we solve the attached question discussed in the class using for loop?