当前位置:网站首页>Calculate the sum of sequences
Calculate the sum of sequences
2022-07-02 11:04:00 【Beauty of algorithm and programming】
Problem description
There's a sequence of scores :2/1,3/2,5/3,8/5,13/8,21/13... Find the front of this sequence 20 Sum of items .
Example :
Input : Enter the first twenty , And take two decimal places .
Output :32.66
2. Algorithm description
Given two starting numbers , Assign values respectively , Then put it into the loop , According to the law , The numerator is the last group of numerators and the denominator , Concurrent recurrence , Until item 20 , Finally, sum , The results of .
3. Experimental discussion and results
Find out the rules , And write a cycle according to the law , Then write the program .
| a=1 b=2 s=0 for I in range(1,21): s+=b/a a , b=b , b +a print(s) print('=%.2f'%s) |
Four . Conclusion
The main consideration of this problem is to find out the rules of numerator and denominator , And put it into the loop , Calculate and get the result .
边栏推荐
- 二叉树专题--洛谷 P3884 [JLOI2009]二叉树问题(dfs求二叉树深度 bfs求二叉树宽度 dijkstra求最短路)
- VSCode工具使用
- 二叉树专题--AcWing 19. 二叉树的下一个节点(找树中节点的后继)
- 【深入浅出玩转FPGA学习3-----基本语法】
- 华为游戏初始化init失败,返回错误码907135000
- 二叉树专题--AcWing 47. 二叉树中和为某一值的路径(前序遍历)
- 长投学堂上面的账户安全吗?
- Nodejs+express+mysql simple blog building
- Special topic of binary tree -- Logu p1229 traversal problem (the number of traversals in the middle order is calculated when the pre and post order traversals of the multiplication principle are know
- C#中索引器
猜你喜欢

Special topic of binary tree -- acwing 3540 Binary search tree building (use the board to build a binary search tree and output the pre -, middle -, and post sequence traversal)

实验电镜距离测量之Matlab处理

V2X-Sim数据集(上海交大&纽约大学)

【快应用】text组件里的文字很多,旁边的div样式会被拉伸如何解决

软件产品管理系统有哪些?12个最佳产品管理工具盘点

全网显示 IP 归属地,是怎么实现的?

Implement custom drawer component in quick application

如何使用IDE自动签名调试鸿蒙应用

最详细MySql安装教程

如何用list组件实现tabbar标题栏
随机推荐
主键策略问题
MySQL keyword
【AppLinking实战案例】通过AppLinking分享应用内图片
Matlab processing of distance measurement of experimental electron microscope
AppGallery Connect场景化开发实战—图片存储分享
华为联机对战服务玩家掉线重连案例总结
华为应用市场应用统计数据问题大揭秘
UVM learning - object attribute of UVM phase
flink二开,实现了个 batch lookup join(附源码)
UVM factory mechanism
学习open62541 --- [66] UA_String的生成方法
洛谷 P1892 [BOI2003]团伙(并查集变种 反集)
【AI应用】海康威视iVMS-4200软件安装
HDU1228 A + B(map映射)
洛谷 P5536 【XR-3】核心城市(贪心 + 树形 dp 寻找树的中心)
OpenMLDB Meetup No.4 会议纪要
Oracle notes
Special topic of binary tree -- acwing 47 Path with a certain value in binary tree (preorder traversal)
2022-06-17
二叉树专题--AcWing 18. 重建二叉树(利用前、中序遍历,构建二叉树)