Input format :
Input gives a real x∈[0,5] in a line.
Output format :
Outputs the partial sum of the power series satisfying the condition in one line, keeping four decimal places.
input sample: < br / > < br / > 1.2 output sample: < br / > < br / > 3.3201 time limit
< br / > 400 ms
```c
#include <stdio.h>
#include <math.h>
int main()
{
double x,xk,sum=1,k=1,i=1;
scanf("%lf", &x);
xk=x;
while (fabs(xk/k)>= 0.00001)
{
sum+=xk/k;
xk*=x;
i++;
k*=i;
}
sum+=xk/k;
printf("%.4lf\n", sum);
}
###### 运行内容超时
###### 用一般算阶乘的方法做,还是超时了,我看到有的博主方法跟我的大相径庭但却是对的
```c
#include <stdio.h>
#include <math.h>
int main()
{
double x,xk,sum=1,k=1,i=1;
scanf("%lf", &x);
xk=x;
while (fabs(xk/k)>= 0.00001)
{
sum+=xk/k;
xk*=x;
i++;
k*=i;
}
sum+=xk/k;
printf("%.4lf\n", sum);
}
不能理解,难到for语句运行时间长一些?
Hope you can show me this konnyaku
0 Answer
No answer yet
这家伙很懒,什么都没留下...