当前位置:网站首页>功能:求出菲波那契数列的前一项与后一项之比的极限的 近似值。例如:当误差为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:放假快乐放假快乐放假快乐放假快乐放假快乐放假快乐放假快乐放假快乐放假快乐放假快乐放假快乐放假快乐
边栏推荐
- Double efficiency. Six easy-to-use pychar plug-ins are recommended
- How to be a professional software testing engineer? Listen to the byte five year old test
- Joint examination of six provinces 2017
- Report on the construction and development mode and investment mode of sponge cities in China 2022-2028
- P1339 [USACO09OCT]Heat Wave G
- Investment demand and income forecast report of China's building ceramics industry, 2022-2028
- (Video + graphics and text) introduction to machine learning series - Chapter 4 naive Bayes
- What is the difference between NFT, SFT and dnft? How to build NFT platform applications?
- What is the GPM scheduler for go?
- What is the potential of pocket network, which is favored by well-known investors?
猜你喜欢

MySQL is installed as a Windows Service

Generic
![[C language] break and continue in switch statement](/img/ae/5967fefcf3262c9d3096e5c7d644fd.jpg)
[C language] break and continue in switch statement

Kubedl hostnetwork: accelerating the efficiency of distributed training communication

(Introduction to database system | Wang Shan) Chapter V database integrity: Exercises

How will the complete NFT platform work in 2022? How about its core functions and online time?

ESP Arduino playing with peripherals (V) basic concept of interrupt and timer interrupt

Cannot build artifact 'test Web: War expanded' because it is included into a circular depend solution

It is forbidden to splice SQL in code

Collation of the most complete Chinese naturallanguageprocessing data sets, platforms and tools
随机推荐
不得不会的Oracle数据库知识点(一)
Sorry, Tencent I also refused
Kubedl hostnetwork: accelerating the efficiency of distributed training communication
What is regression testing? Talk about regression testing in the eyes of Ali Test Engineers
Ningde times and BYD have refuted rumors one after another. Why does someone always want to harm domestic brands?
Double efficiency. Six easy-to-use pychar plug-ins are recommended
【leetcode】300. Longest increasing subsequence (dynamic programming, dichotomy)
[2021]NeRF in the Wild: Neural Radiance Fields for Unconstrained Photo Collections
1214 print diamond
Collation of the most complete Chinese naturallanguageprocessing data sets, platforms and tools
CSP window
Qtcharts notes (V) scatter diagram qscatterseries
Report on the construction and development mode and investment mode of sponge cities in China 2022-2028
ESP Arduino playing with peripherals (V) basic concept of interrupt and timer interrupt
It is forbidden to splice SQL in code
Iclr2022: how does AI recognize "things I haven't seen"?
URL (data:image/png; Base64, ivborw0k... Use case
How will the complete NFT platform work in 2022? How about its core functions and online time?
Ningde times and BYD have refuted rumors one after another. Why does someone always want to harm domestic brands?
Global and Chinese market of underwater bags 2022-2028: Research Report on technology, participants, trends, market size and share