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

你可能感兴趣的文章
python | bashplotlib,一个有趣的Python库!
查看>>
python | bentoml,一个超级厉害的 模型部署 Python 库!
查看>>
python调用jar包的模块_python调用jar包
查看>>
python | black,一个神奇的 代码格式化工具 Python 库!
查看>>
python | bleach,一个超强的 Python 库!
查看>>
python | cartopy,一个有趣的 Python 库!
查看>>
python | cloud-init,一个实用的 云计算 Python 库!
查看>>
python | code2flow,一个神奇的 Python 库!
查看>>
python | cudf,一个超实用的 Python 库!
查看>>
python | daphne,一个非常nice的 Python 库!
查看>>
python调用halcon
查看>>
python | doit,一个非常实用的 Python 库!
查看>>
python | easyocr,一个超厉害的 关于OCR的 Python 库!
查看>>
python | fastFM,一个高级的 Python 库!
查看>>
python | feature_engine,一个实用的 Python 库!
查看>>
python | filelock,一个超酷的 Python 库!
查看>>
python | fire,一个强大的 Python 库!
查看>>
python | flanker,一个神奇的 Python 库!
查看>>
python | flower,一个强大的 Python 库!
查看>>
python | funcy,一个超强的 提供函数式编程工具 Python 库!
查看>>