解题思路:
注意事项:
参考代码:
#include <stdio.h>
#include <math.h>
#define LONG 10
int main()
{
double fact(int n);
double mypow(double x, int n);
double x,S=0; int n;
scanf("%lf %d", &x, &n);
for (int i = 1; i <= n; i++)
S =S+ mypow(-1, i-1)*mypow(x,i) / fact(i);
printf("%.4lf", S);
return 0;
}
double fact(int n)
{
double count = 1;
while (n != 0)
{
count = count * n;
n--;
}
return count;
}
double mypow(double x, int n)
{
double count=1;
while (n != 0)
{
count = count * x;
n--;
}
return count;
}
0.0分
2 人评分