C语言
求y=x+x的二次方/2+x的三次方/3+….+x的n次方/n
(x的绝对值小于1)
参考如下:
#include<stdio.h>
int main()
{
int n;
double x, y = 0;
printf("Input x: ");
scanf("%lf", &x);
printf("Input n: ");
scanf("%d", &n);
double t = x;
for (int i = 1; i <= n; i++)
{
y += t * 1.0 / i;
t *= x;
}
printf("y=%lf", y);
return 0;
}