C语言问题,高分悬赏!!!

来源:百度知道 编辑:UC知道 时间:2024/05/23 16:09:20
做一个计算log(1+ x)=∑(-1)的n-1次方在乘以x的n次方除以n的C语言程序,(n=1、2、3.....n, x不等于-1,因为次方无法打出来所以用语言描述)。要求如下:

1 为了和上式求出来的值作比较,输入x的值之后,用标准函数log( )求出式子的值,将它作为E。

2 输入底数N的值,t的时候(1<t<N),输入t之后由上式算出来的值,将它作为V,然后将误差e=|E-V/E|从文件“result.csv”输出即可!

运行后要如下:

%a.exe
Please input x value: 0.3 (← 输入x的值)
Please input number of terms: 10 (← 输入N的值)
log(1.000000+0.300000) equals 0.262364 (← 输出E的值)
Data was output on the file.
(注:a.exe和0.3和10要求从键盘输入)

result.csv如下:

1, 0.3000000000, 0.1434484060
2, 0.2550000000, 0.0280688549
3, 0.2640000000, 0.0062345973
4, 0.2619750000, 0.0014836794
5, 0.2624610000, 0.0003687070
6, 0.2623395000, 0.0000943896
7, 0.2623707429, 0.0000246923
8, 0.2623625416, 0.0000065667
9, 0.2623647286, 0.0000017691
10, 0.2623641381, 0.0000004816

谢谢给我解决问题的大哥大姐了!我是初学者,用简单易懂的做法即可! 谢谢啦!要是好的话,在加分!

#include <stdio.h>
#include <stdlib.h>
#include <math.h>

void main(int argc, char *argv[])
{
double x,t,sum=0.0;
int i,j,N;
double e;
FILE *fout;

printf("\nPlease input x value: ");
scanf("%lf",&x);
e = log(1+x);
printf("\nPlease input number of terms: ");
scanf("%d",&N);
printf("log(1.000000+%lf) equals %lf\n\n",x,e);

fout = fopen("result.csv","w");

t = x;sum = t;
fprintf(fout,"1,%.10lf,%.10lf\n",sum, fabs(sum/e-1.0));
for (i=2;i<=N;i++){
t = t * x /(double) i * (i-1)* (-1);
sum = sum + t;
fprintf(fout,"%d,%.10lf,%.10lf\n",i,sum,fabs(sum/e-1.0));
}
fclose(fout);
printf("output in result.csv\n");
system("pause");
}

你是初学者?
这不像初学者做的题阿