博客
关于我
浙大版《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 resource identifier found for attribute 'srcCompat' in package的解决办法
查看>>
no session found for current thread
查看>>
No static resource favicon.ico.
查看>>
no such file or directory AndroidManifest.xml
查看>>
No toolchains found in the NDK toolchains folder for ABI with prefix: mips64el-linux-android
查看>>
NO.23 ZenTaoPHP目录结构
查看>>
no1
查看>>
NO32 网络层次及OSI7层模型--TCP三次握手四次断开--子网划分
查看>>
NOAA(美国海洋和大气管理局)气象数据获取与POI点数据获取
查看>>
NoClassDefFoundError: org/springframework/boot/context/properties/ConfigurationBeanFactoryMetadata
查看>>
node exporter完整版
查看>>
node HelloWorld入门篇
查看>>
Node JS: < 一> 初识Node JS
查看>>
Node JS: < 二> Node JS例子解析
查看>>
Node Sass does not yet support your current environment: Linux 64-bit with Unsupported runtime(93)解决
查看>>
Node Sass does not yet support your current environment: Windows 64-bit with Unsupported runtime(72)
查看>>
Node 裁切图片的方法
查看>>
node+express+mysql 实现登陆注册
查看>>
Node+Express连接mysql实现增删改查
查看>>
node, nvm, npm,pnpm,以前简单的前端环境为什么越来越复杂
查看>>