迭代法,是一种不断用变量的旧值递推新值的过程。
fun函数设置循环,当x0-x1的绝对值小于0.000001循环结束。
#include
<stdio.h>
#include
<math.h>
float
fun()
{float
x,n=0.0,root;
while(root>=0.000001||root<=-0.000001)
{
x=n;
n=cos(x);
root=x-n;
}
root=n;
return
root
;
}
void
main()
{
float
f=fun();
printf("root=%f\n",f);
}
温馨提示:答案为网友推荐,仅供参考