博客
关于我
浙大版《C语言程序设计(第3版)》题目集 练习2-15
阅读量:118 次
发布时间:2019-02-26

本文共 518 字,大约阅读时间需要 1 分钟。

练习2-15 求简单交错序列前N项和 (15分)

本题要求编写程序,计算序列 1 - 1/4 + 1/7 - 1/10 + … 的前N项之和。

输入格式:
输入在一行中给出一个正整数N。
输出格式:
在一行中按照“sum = S”的格式输出部分和的值S,精确到小数点后三位。题目保证计算结果不超过双精度范围。
输入样例:
10
输出样例:
sum = 0.819
作者
C课程组
单位
浙江大学
代码长度限制
16 KB
时间限制
400 ms
内存限制
64 MB

#include 
#include
int main() { int n, i, d = 1; double sum = 0; if (scanf("%d", &n) == 1) { for (i = 1; i <= n; i++) { sum += pow(-1, i + 1) * 1.0 / d; d += 3; } printf("sum = %.3f", sum); } return 0;}

转载地址:http://cvzu.baihongyu.com/

你可能感兴趣的文章
No 'Access-Control-Allow-Origin' header is present on the requested resource.
查看>>
NO 157 去掉禅道访问地址中的zentao
查看>>
no available service ‘default‘ found, please make sure registry config corre seata
查看>>
No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?
查看>>
no connection could be made because the target machine actively refused it.问题解决
查看>>
No Datastore Session bound to thread, and configuration does not allow creation of non-transactional
查看>>
No fallbackFactory instance of type class com.ruoyi---SpringCloud Alibaba_若依微服务框架改造---工作笔记005
查看>>
No Feign Client for loadBalancing defined. Did you forget to include spring-cloud-starter-loadbalanc
查看>>
No mapping found for HTTP request with URI [/...] in DispatcherServlet with name ...的解决方法
查看>>
No mapping found for HTTP request with URI [/logout.do] in DispatcherServlet with name 'springmvc'
查看>>
No module named 'crispy_forms'等使用pycharm开发
查看>>
No module named 'pandads'
查看>>
No module named cv2
查看>>
No module named tensorboard.main在安装tensorboardX的时候遇到的问题
查看>>
No module named ‘MySQLdb‘错误解决No module named ‘MySQLdb‘错误解决
查看>>
No new migrations found. Your system is up-to-date.
查看>>
No qualifying bean of type XXX found for dependency XXX.
查看>>
No qualifying bean of type ‘com.netflix.discovery.AbstractDiscoveryClientOptionalArgs<?>‘ available
查看>>
No resource identifier found for attribute 'srcCompat' in package的解决办法
查看>>
no session found for current thread
查看>>