I'm writing code to find square root of numbers using Newton–Raphson method but I can't get the correct output.
When I run this code with any input, I get 0.000003 as result without any errors or alarms.
When I change all double
keywords to float
it works correctly.
double square(double n)
{
register int i;
double x = 0.1;
for (i = 1; i <= 15; i++)
x -= ((x * x - n) / (2 * x));
return x;
}
int main()
{
double n;
system("cls");
printf("enter a num : ");
scanf("%f",&n);
printf("\n square is : %f",square(n));
getch();
return 0;
}