博客
关于我
浙大版《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/

你可能感兴趣的文章
mysql5.7 for windows_MySQL 5.7 for Windows 解压缩版配置安装
查看>>
mysql5.7性能调优my.ini
查看>>
mysql5.7的安装和Navicat的安装
查看>>
MySQL8.0.29启动报错Different lower_case_table_names settings for server (‘0‘) and data dictionary (‘1‘)
查看>>
MySQL8修改密码报错ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
查看>>
mysqlbinlog报错unknown variable ‘default-character-set=utf8mb4‘
查看>>
mysqldump 导出中文乱码
查看>>
mysqldump备份时忽略某些表
查看>>
mysqlreport分析工具详解
查看>>
MySQL一个表A中多个字段关联了表B的ID,如何关联查询?
查看>>
MYSQL一直显示正在启动
查看>>
MySQL一站到底!华为首发MySQL进阶宝典,基础+优化+源码+架构+实战五飞
查看>>
MySQL万字总结!超详细!
查看>>
Mysql下载以及安装(新手入门,超详细)
查看>>
mysql中cast() 和convert()的用法讲解
查看>>
mysql中floor函数的作用是什么?
查看>>
MySQL中group by 与 order by 一起使用排序问题
查看>>
mysql中having的用法
查看>>
mysql中int、bigint、smallint 和 tinyint的区别、char和varchar的区别详细介绍
查看>>
mysql中json_extract的使用方法
查看>>