当前位置:网站首页>功能:求出菲波那契数列的前一项与后一项之比的极限的 近似值。例如:当误差为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:放假快乐放假快乐放假快乐放假快乐放假快乐放假快乐放假快乐放假快乐放假快乐放假快乐放假快乐放假快乐
边栏推荐
- Qtcharts notes (V) scatter diagram qscatterseries
- Generic tips
- MySQL is installed as a Windows Service
- Reading notes on how programs run
- ITK learning notes (VII) the position of ITK rotation direction remains unchanged
- [error record] configure NDK header file path in Visual Studio
- 1214 print diamond
- Pytorch learning notes 5: model creation
- Smart fan system based on stm32f407
- 不得不会的Oracle数据库知识点(二)
猜你喜欢

Struct in linked list

What is regression testing? Talk about regression testing in the eyes of Ali Test Engineers

It is worthy of "Alibaba internal software test interview notes" from beginning to end, all of which are essence

Collation of the most complete Chinese naturallanguageprocessing data sets, platforms and tools

What is the Valentine's Day gift given by the operator to the product?

Analysis: misunderstanding of choosing WMS warehouse management system

The FISCO bcos console calls the contract and reports an error does not exist

SPI based on firmware library

Analysis on the scale of China's smart health industry and prediction report on the investment trend of the 14th five year plan 2022-2028 Edition

Briefly understand the operation mode of developing NFT platform
随机推荐
Global and Chinese market of breast cancer imaging 2022-2028: Research Report on technology, participants, trends, market size and share
网上的低佣金链接安全吗?招商证券怎么开户?
Correlation analysis summary
Unity elementary case notes of angry birds Siki college 1-6
China standard gas market prospect investment and development feasibility study report 2022-2028
Selenium library 4.5.0 keyword explanation (II)
Anomalies seen during the interview
What is the future of software testing industry? Listen to the test veterans' answers
Version rollback revert don't reset better reset must be forced
Optimization of for loop
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
A dichotomy of Valentine's Day
Global and Chinese market of glossometer 2022-2028: Research Report on technology, participants, trends, market size and share
老姜的特点
2022 system integration project management engineer examination knowledge points: software development model
Five high-frequency questions were selected from the 200 questions raised by 3000 test engineers
Ningde times and BYD have refuted rumors one after another. Why does someone always want to harm domestic brands?
Is user authentication really simple
Report on prospects and future investment recommendations of China's assisted reproductive industry, 2022-2028 Edition
What are the application fields of digital twins in industry?