首页 > 其他 > 详细

练习2-13 求N分之一序列前N项和 (15 分)

时间:2019-06-30 21:15:20      阅读:158      评论:0      收藏:0      [点我收藏+]

练习2-13 求N分之一序列前N项和 (15 分)

输入在一行中给出一个正整数N。

输出格式:

在一行中按照“sum = S”的格式输出部分和的值S,精确到小数点后6位。题目保证计算结果不超过双精度范围。

输入样例:

6

输出样例:

sum = 2.450000


 1 #include <stdio.h>
 2 #include <stdlib.h>
 3 
 4 
 5 /* run this program using the console pauser or add your own getch, system("pause") or input loop */
 6 
 7 int main(int argc, char *argv[]) {
 8 int x;
 9 double s=0,y;
10 scanf("%d",&x);
11 
12 for(y=1;y<=x;y++){
13 s+=1.0/y;
14 }
15 printf("sum = %.6f\n",s);
16 return 0;
17 }

 

 
 

练习2-13 求N分之一序列前N项和 (15 分)

原文:https://www.cnblogs.com/xxl-h/p/11111022.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!