当前位置:网站首页>功能:求出菲波那契数列的前一项与后一项之比的极限的 近似值。例如:当误差为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:放假快乐放假快乐放假快乐放假快乐放假快乐放假快乐放假快乐放假快乐放假快乐放假快乐放假快乐放假快乐
边栏推荐
- Global and Chinese market of process beer equipment 2022-2028: Research Report on technology, participants, trends, market size and share
- Anomalies seen during the interview
- Is the account opening of Guoyuan securities really safe and reliable
- MySQL 8.0.12 error: error 2013 (HY000): lost connection to MySQL server during query
- Interview script of Software Test Engineer
- Struct in linked list
- ESP Arduino playing with peripherals (V) basic concept of interrupt and timer interrupt
- How will the complete NFT platform work in 2022? How about its core functions and online time?
- Att & CK actual combat series - red team actual combat - V
- Celebrate the new year | Suihua fire rescue detachment has wonderful cultural activities during the Spring Festival
猜你喜欢
A dichotomy of Valentine's Day
NLP Chinese corpus project: large scale Chinese natural language processing corpus
Report on the construction and development mode and investment mode of sponge cities in China 2022-2028
Detailed explanation of the relationship between Zhongtai, wechat and DDD
MySQL 8.0.12 error: error 2013 (HY000): lost connection to MySQL server during query
Shell script three swordsman sed
Qtcharts notes (V) scatter diagram qscatterseries
It is the most difficult to teach AI to play iron fist frame by frame. Now arcade game lovers have something
老姜的特点
SPI based on firmware library
随机推荐
Generic tips
Version rollback revert don't reset better reset must be forced
(Video + graphics and text) introduction to machine learning series - Chapter 4 naive Bayes
[software testing] you haven't mastered these real interview questions of big companies?
Entropy and full connection layer
不得不会的Oracle数据库知识点(三)
P1629 postman delivering letter
MySQL 8.0.12 error: error 2013 (HY000): lost connection to MySQL server during query
Wechat official account and synchronization assistant
挖财帮个人开的证券账户安全吗?是不是有套路
Solve the problem that the kaggle account registration does not display the verification code
Is the low commission link on the internet safe? How to open an account for China Merchants Securities?
Idea set class header comments
[C language] break and continue in switch statement
[about text classification trick] things you don't know
P1656 bombing Railway
Global and Chinese markets for blood and liquid heating devices 2022-2028: Research Report on technology, participants, trends, market size and share
Severity code description the project file line prohibits the display of status error c4996 fopen ('fscanf ', StrCmp): this function or variable may be unsafe The most comprehensive solution
Kubedl hostnetwork: accelerating the efficiency of distributed training communication
Optimization of for loop