Hyunebee
지수와 로그 본문
제곱과 제곱근
우리가 자주 사용하는 Math를 대신해 바빌로니아 점화식으로 제곱근을 구할 수 있다.
public class Practice {
static double sqrt(int a, int n){
double result = 1;
for(int i = 0; i <= n; i++){
result = (result + a/result) / 2;
}
return result;
}
public static void main(String[] args) {
System.out.println(sqrt(14 , 99));
System.out.println(Math.sqrt(14));
}
}
제곱근은 가장 근접한 숫자를 찾는것 임으로 반복할수록 정확도는 높아진다.