compute x to the power n using while loop