C语音复习PPT IE循环结构程序.pptxVIP

  • 0
  • 0
  • 约2.8千字
  • 约 15页
  • 2021-11-02 发布于江苏
  • 举报
课件封面;实验教学标题;3 循环结构程序;#include stdio.h #include math.h void main() { double e0, e=1.0; // 累加和初值为 1 double t=1.0 ; // 累乘初值为 1 int n=0 ; do { e0= e ; n = n + 1 ; // 计算数列分母 t = t / n ; // 计算数列项 e = e + t ; // 计算累加和 } while (fabs(e-e0)1e-6) ; //计算误差,如果大于1e-6继续做下去 printf(e值为:%lf\n , e); };3 循环结构程序;#include stdio.h void main() { int i ,n=1,m=1 ,t ; double s=0 ; //累加和初值必为0 for (i=1 ; i=20 ; i++) {t = n ; // 将前一项的分母临时保存下来 n = m ; // 当前项的分母是前一项的分子 m = t+m ; // 当前项的分子是前一项的分子加前一项的分母 s = s + (double)m/n ; // 计算累加 } printf(数列前20项的值是:%f\n , s); };3 循环结构程序;include s

文档评论(0)

1亿VIP精品文档

相关文档