博客
关于我
PTA浙大版《C语言程序设计(第3版)》题目集习题2-3 求平方与倒数序列的部分和
阅读量:318 次
发布时间:2019-03-03

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

编写一个程序来计算平方与倒数序列的部分和。

首先,读取输入的两个正整数m和n(m≤n)。

然后,初始化一个double变量sum为0.0。

接下来,循环从m到n,计算每一项的值k² + 1/k,并将其加到sum中。

最后,输出sum,保留六位小数。

以下是所需代码:

#include 
#include
int main() { int m, n; double sum = 0.0; scanf("%d %d", &m, &n); for (; m <= n; m++) { sum += pow(m, 2) + 1.0 / m; } printf("sum = %.6lf", sum); return 0;}

输入样例:5 10

输出样例:sum = 355.845635

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

你可能感兴趣的文章
Prometheus 黑盒监控实战
查看>>
prometheus+alertmanager+grafana监控部署教程
查看>>
Prometheus+Grafana构建智能化Kubernetes监控系统实战
查看>>
Prometheus+SpringBoot应用监控全过程详解
查看>>
Prometheus+SpringBoot应用监控全过程详解
查看>>
prometheus安装
查看>>
Prometheus实战教程:监控Kafka消息
查看>>
Prometheus实战教程:监控mysql数据库
查看>>
Prometheus实战教程:监控Nginx状态
查看>>
prometheus常用exporter下载地址大全
查看>>
Prometheus快速搭建与监控Linux系统实战
查看>>
prometheus报警与恢复告警的格式
查看>>
Pytorch中安装 torch_geometric 详细图文操作(全)
查看>>
prometheus监控docker容器实战
查看>>
Prometheus监控k8s集群使用邮箱和微信告警!
查看>>
Prometheus监控mysq数据库实战
查看>>
prometheus监控nginx实战
查看>>
Prometheus监控redis数据库实战
查看>>
Prometheus监控教程:使用Grafana展示主机基本信息
查看>>
pytorch中如何使用预训练词向量
查看>>