博客
关于我
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/

你可能感兴趣的文章
TCP基本入门-简单认识一下什么是TCP
查看>>
tableviewcell 中使用autolayout自适应高度
查看>>
Symbolic Aggregate approXimation(SAX,符号聚合近似)介绍-ChatGPT4o作答
查看>>
Orcale表被锁
查看>>
svn访问报错500
查看>>
Orderer节点启动报错解决方案:Not bootstrapping because of 3 existing channels
查看>>
org.apache.ibatis.exceptions.PersistenceException:
查看>>
org.apache.ibatis.exceptions.TooManyResultsException: Expected one result (or null) to be returned
查看>>
org.apache.ibatis.type.TypeException: Could not resolve type alias 'xxxx'异常
查看>>
org.apache.poi.hssf.util.Region
查看>>
org.apache.xmlbeans.XmlOptions.setEntityExpansionLimit(I)Lorg/apache/xmlbeans/XmlOptions;
查看>>
org.apache.zookeeper.KeeperException$ConnectionLossException: KeeperErrorCode = ConnectionLoss for /
查看>>
org.hibernate.HibernateException: Unable to get the default Bean Validation factory
查看>>
org.hibernate.ObjectNotFoundException: No row with the given identifier exists:
查看>>
SQL-CLR 类型映射 (LINQ to SQL)
查看>>
org.springframework.orm.hibernate3.support.OpenSessionInViewFilter
查看>>
org.springframework.orm.hibernate3.support.OpenSessionInViewFilter
查看>>
org.springframework.web.multipart.MaxUploadSizeExceededException: Maximum upload size exceeded
查看>>
org.tinygroup.serviceprocessor-服务处理器
查看>>
org/eclipse/jetty/server/Connector : Unsupported major.minor version 52.0
查看>>