当前位置:网站首页>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 .
边栏推荐
- Use Huawei performance management service to configure the sampling rate on demand
- 二叉树专题--P1030 [NOIP2001 普及组] 求先序排列
- 使用华为性能管理服务,按需配置采样率
- flink二開,實現了個 batch lookup join(附源碼)
- Special topic of binary tree -- acwing 1589 Building binary search tree
- 华为AppLinking中统一链接的创建和使用
- Thanos Receiver
- UVM factory mechanism
- Creation and use of unified links in Huawei applinking
- js数组常用方法
猜你喜欢

Shell programming 01_ Shell foundation

JVM之垃圾回收器

Leetcode+ 76 - 80 storm search topic

Creation and use of unified links in Huawei applinking
![[play with FPGA learning 5 in simple terms ----- reset design]](/img/57/816a59787259dc32b52897c069e1a6.png)
[play with FPGA learning 5 in simple terms ----- reset design]
![[play with FPGA learning 4 in simple terms ----- talk about state machine design]](/img/e0/95f8b8c5116c57455e54ad12372f12.png)
[play with FPGA learning 4 in simple terms ----- talk about state machine design]

Mysql database remote access permission settings
![[TS] 1368 seconds understand typescript generic tool types!](/img/2b/58a850b52ce8a9b2e6e7b6b72b0fe5.jpg)
[TS] 1368 seconds understand typescript generic tool types!

Open the encrypted SQLite method with sqlcipher

二叉树专题--洛谷 P1229 遍历问题(乘法原理 已知前、后序遍历求中序遍历个数)
随机推荐
[play with FPGA learning 4 in simple terms ----- talk about state machine design]
[AGC] build service 3 - authentication service example
首份中国企业敏捷实践白皮书发布| 附完整下载
[ark UI] implementation of the startup page of harmonios ETS
华为AppLinking中统一链接的创建和使用
全网显示 IP 归属地,是怎么实现的?
UVM——Callback
P1055 [NOIP2008 普及组] ISBN 号码
[applinking practical case] share in app pictures through applinking
Jsp webshell Free from killing - The Foundation of JSP
Set the playback speed during the playback of UOB equipment
2022-06-17
Hdu1228 a + B (map mapping)
Common methods of JS array
Open the encrypted SQLite method with sqlcipher
Leetcode 182 Find duplicate email (2022.07.01)
Analysis of hot spots in AI technology industry
Logu p3398 hamster looks for sugar (double LCA on the tree to judge whether the two paths in the tree intersect)
V2X-Sim数据集(上海交大&纽约大学)
长投学堂上面的账户安全吗?