下列程序的功能是:利用以下所示的简单迭代方法求方程:
cos(x)-x=0的一个实根。
xn+1=cos(xn)
迭代步骤如下;
(1)取x1初值为0.0。
(2)x0=x1,把x1的值赋给x0。
(3)x1=cos(x0),求出一个新的x1。
(4)若x0-x1的绝对值小于0.000001,执行步骤(5),否则执行步骤(2)。
(5)所求x1就是方程cos(x)-x=0的一个实根,作为函数值返回。
请编写函数countValue()实现程序要求,最后调用函数writeDAT()把结果输出到文件out41.dat中。
注意;部分源程序已给出。
请勿改动主函数main()和写函数writeDAT()的内容。
试题程序:
#include<conio.h>
#include<math.h>
#include<stdio.h>
float countValue( )
main ( )
clrscr( );
printf("实根=%f\n",countValue( ));
printf("%f\n",cos(countValue( ))-countValue( ));
writeDAT( );
writeDAT( )
FILE *wf;
wf=fopen("out41.dat","w");
fprintf(wf,"%f\n",countValue( ));
fclose(wf);