Iterative method
/*
==================================================================
Title: Newton Iterative method to find the square root of a! Iterative formula: xn+1= (XN+A/XN)/2.
==================================================================
*/
#include <stdio.h>
#include <math.h>
Main ()
{
float a,x0,x1;
int flag=1;
while (flag)
{
printf ("a=");
scanf ("%f", &a);
if (a>=0)
flag=0;
Else
printf ("You cannot enter the number of square root, please try again!") \n_______________________________\n\n ");
}
X0=1;
x1=x0+1;
while (Fabs (x0-x1) >=1e-10)
{
x0=x1;
x1=0.5* (x0+a/x0);
}
printf ("The square root of the%.2f is:%.2f\n", a,x1);
}
/*
==================================================================
Comment: The essence is iterative method, first enter the number a that meets the condition, give x0 and X1 assignment, make the absolute value of the difference
Greater than 10-10 times. Use an iterative formula to make the difference between x0 and X1 when the errand is greater than or equal to 10-10 times
Less than 10-10 times. The square root is x1 or x0.
==================================================================
*/
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
The basic algorithm of C language 11-Newton iterative method to find square root