当前位置:网站首页>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 .
边栏推荐
- JVM garbage collector
- VSCode工具使用
- P1055 [NOIP2008 普及组] ISBN 号码
- 二叉树专题--AcWing 1497. 树的遍历(利用后、中序遍历,构建二叉树)
- Disassembling Meitu SaaS: driving the plane to change the engine
- JSP webshell免殺——JSP的基礎
- 【AGC】构建服务3-认证服务示例
- Nodejs+express+mysql simple blog building
- QT学习日记8——资源文件添加
- How to use ide to automatically sign and debug Hongmeng application
猜你喜欢
MySQL environment configuration
Kustomize user manual
Jsp webshell Free from killing - The Foundation of JSP
618 what is the secret of dominating the list again? Nike's latest financial report gives the answer
Leetcode+ 76 - 80 storm search topic
The URL in the RTSP setup header of the axis device cannot take a parameter
[SUCTF2018]followme
二叉树专题--AcWing 3540. 二叉搜索树建树(实用板子 构建二叉搜索树 并输出前、中、后序遍历)
Shell programming 01_ Shell foundation
MongoDB 学习整理(条件操作符,$type 操作符,limit()方法,skip() 方法 和 sort() 方法)
随机推荐
Point cloud projection picture
【ARK UI】HarmonyOS ETS的启动页的实现
【AppLinking实战案例】通过AppLinking分享应用内图片
HDU1228 A + B(map映射)
2022-06-17
The most detailed MySQL installation tutorial
【AGC】构建服务3-认证服务示例
力扣(LeetCode)182. 查找重复的电子邮箱(2022.07.01)
Convert yv12 to rgb565 image conversion, with YUV to RGB test
Summary of cases of players' disconnection and reconnection in Huawei online battle service
Shell programming 01_ Shell foundation
How to use ide to automatically sign and debug Hongmeng application
PCL之滤波
[play with FPGA learning 5 in simple terms ----- reset design]
How to implement tabbar title bar with list component
From Read and save in bag file Jpg pictures and PCD point cloud
【快应用】Win7系统使用华为IDE无法运行和调试项目
从.bag文件中读取并保存.jpg图片和.pcd点云
2022爱分析· 国央企数字化厂商全景报告
HDU1234 开门人和关门人(水题)