当前位置:网站首页>功能:求出菲波那契数列的前一项与后一项之比的极限的 近似值。例如:当误差为0.0001时,函数值为0.618056。
功能:求出菲波那契数列的前一项与后一项之比的极限的 近似值。例如:当误差为0.0001时,函数值为0.618056。
2022-07-04 00:34:00 【CTGU-Yoghurt】
题目:
首先解释一下什么叫斐波那契数列:
(这里引用我的一个朋友写的图片)

简单来说就是
第1项和第2项为1,从后面开始每一项是前面两项的和。
以此类推组成的数列。
代码详解:
#include <stdio.h>
#include "math.h"
float fun()
{
/**********Program**********/
float f1 = 1, f2 = 1,f3=2,t;//
f1代表第1项,f2代表第2项,f3代表第3项
while (fabs(f2/f3 - f1/f2) > 0.0001) {
f1 = f2;
t = f2 + f3;
f2 = f3;
f3 = t;
}
return f2/f3;//方法1
/*float f1 = 1, f2 = 1, f3;
float r1 = 2, r2;
do
{
r2 = r1;
r1 = f1 / f2;
f3 = f1 + f2;
f1 = f2;
f2 = f3;
} while (fabs(r1 - r2) > 1e-4);
return r1;*///方法2
/********** End **********/
}
int main()
{
printf("y=%f\n", fun());
}
PS:放假快乐放假快乐放假快乐放假快乐放假快乐放假快乐放假快乐放假快乐放假快乐放假快乐放假快乐放假快乐
边栏推荐
- Selenium library 4.5.0 keyword explanation (II)
- (Introduction to database system | Wang Shan) Chapter V database integrity: Exercises
- China standard gas market prospect investment and development feasibility study report 2022-2028
- Advanced C language - pointer 2 - knowledge points sorting
- Global and Chinese market of underwater bags 2022-2028: Research Report on technology, participants, trends, market size and share
- Selenium library 4.5.0 keyword explanation (4)
- NLP Chinese corpus project: large scale Chinese natural language processing corpus
- What is regression testing? Talk about regression testing in the eyes of Ali Test Engineers
- Generic
- The upload experience version of uniapp wechat applet enters the blank page for the first time, and the page data can be seen only after it is refreshed again
猜你喜欢

Private project practice sharing populate joint query in mongoose makes the template unable to render - solve the error message: syntaxerror: unexpected token r in JSON at
![[complimentary ppt] kubemeet Chengdu review: make the delivery and management of cloud native applications easier!](/img/28/fc05f2e8d53cf81fd061c799090022.jpg)
[complimentary ppt] kubemeet Chengdu review: make the delivery and management of cloud native applications easier!

Ningde times and BYD have refuted rumors one after another. Why does someone always want to harm domestic brands?

The difference between objects and objects
![Docking Alipay process [pay in person, QR code Payment]](/img/30/665580241020ee3adb872e725f0624.jpg)
Docking Alipay process [pay in person, QR code Payment]

Unity elementary case notes of angry birds Siki college 1-6

Ningde times and BYD have refuted rumors one after another. Why does someone always want to harm domestic brands?

MySQL is installed as a Windows Service

Alibaba test engineer with an annual salary of 500000 shares notes: a complete set of written tests of software testing

Sorry, Tencent I also refused
随机推荐
Stock price forecast
2022 system integration project management engineer examination knowledge points: software development model
What is the potential of pocket network, which is favored by well-known investors?
不得不会的Oracle数据库知识点(二)
Interview script of Software Test Engineer
I would like to ask how the top ten securities firms open accounts? Is it safe to open an account online?
Idea set class header comments
What is regression testing? Talk about regression testing in the eyes of Ali Test Engineers
2020.2.14
[PHP basics] cookie basics, application case code and attack and defense
[BSP video tutorial] stm32h7 video tutorial phase 5: MDK topic, system introduction to MDK debugging, AC5, AC6 compilers, RTE development environment and the role of various configuration items (2022-
From functional testing to automated testing, how did I successfully transform my salary to 15K +?
MySQL winter vacation self-study 2022 12 (2)
CSP window
不得不会的Oracle数据库知识点(一)
【leetcode】374. Guess the size of the number
Wechat official account and synchronization assistant
[about text classification trick] things you don't know
Speed up the energy Internet of things. What can low-power Internet of things technology represented by Zeta do?
ITK learning notes (VII) the position of ITK rotation direction remains unchanged