、绘制流程图,实现sum=1/1!+1/2!+1/3!-+……+1/10!
时间: 2024-01-30 20:01:35 浏览: 79
以下是C语言实现求和的流程图:
```flow
st=>start: 开始
in=>inputoutput: 输入x和n的值
op1=>operation: 初始化sum、zi、mu为1
op2=>operation: 计算zi=pow(x,i)
op3=>operation: 计算mu=mu*j
op4=>operation: 计算sum=sum+zi/mu
cond=>condition: i<=n?
out=>inputoutput: 输出sum
e=>end: 结束
st->in->op1->op2->op3->op4->cond
cond(yes)->op2
cond(no)->out->e
```
以下是C语言实现求和的代码:
```c
#include <stdio.h>
#include <math.h>
int main() {
int i, j;
int x, n;
double sum = 1, zi = 1, mu = 1;
scanf("%d %d", &x, &n);
for (i = 1; i <= n; i++) {
zi = pow(x, i);
for (j = 1; j <= i; j++)
mu = mu * j;
sum = sum + zi / mu; mu = 1;
}
printf("%lf", sum);
printf("\n");
return 0;
}
```
阅读全文