Bank of America interview question

Tell me the entire function to calculate square root of any integer without using any library function?

Interview Answer

Anonymous

26 Jul 2017

public static double sqrt(int num){ double t; double sq = num/2; do{ t = sq; sq = (t+(num/t)) / 2; } while((t-sq) != 0); return sq; }