#include <stdio.h>
#include <math.h>
int main()
{
double x, a0,a1,f,fd;
x=1.0;
FILE *fp;//建立一个文件操作指针
fp=fopen("1.txt","w+");//以追加的方式建立或打开1.txt,默认位置在你程序的目录下面
do
{a0=x;
f=((a0-18)*a0+95)*a0-150;
fd=(3*a0-36)*a0+95;
x=a0-f/fd;
} while(x-a0>=1.e-5);
printf("\nx=%.6f",x);
fprintf(fp,"\nx=%.6f",x);//同输出printf一样,以格式方式输出到文本中
fclose(fp);//关闭流
}
#include <math.h>
int main()
{
double x, a0,a1,f,fd;
x=1.0;
FILE *fp;//建立一个文件操作指针
fp=fopen("1.txt","w+");//以追加的方式建立或打开1.txt,默认位置在你程序的目录下面
do
{a0=x;
f=((a0-18)*a0+95)*a0-150;
fd=(3*a0-36)*a0+95;
x=a0-f/fd;
} while(x-a0>=1.e-5);
printf("\nx=%.6f",x);
fprintf(fp,"\nx=%.6f",x);//同输出printf一样,以格式方式输出到文本中
fclose(fp);//关闭流
}