본문 바로가기

Programming/Algorithm

root 계산 함수 만들기

원문 : http://blog.daum.net/_blog/BlogTypeView.do?blogid=0Xrxs&articleno=41




#include <stdio.h>

double SQRT(double, double);

void main()
{
 double input, x, result;
    while(1)
    {
        scanf("%lf", &input);
        scanf("%lf", &x);
        result = SQRT(input, x);
        printf("제곱근은? : %lf \n", result); 
     }
}


double SQRT(double input, double x)
{
      for(int i=0; i<10; i++) {  x = (x + (input / x)) / 2 ; }

 return x ;
}