当前位置:网站首页>功能:求出菲波那契数列的前一项与后一项之比的极限的 近似值。例如:当误差为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:放假快乐放假快乐放假快乐放假快乐放假快乐放假快乐放假快乐放假快乐放假快乐放假快乐放假快乐放假快乐
边栏推荐
- Pytorch learning notes 5: model creation
- I would like to ask how the top ten securities firms open accounts? Is it safe to open an account online?
- Introduction to thread pool
- Pair
- Report on the construction and development mode and investment mode of sponge cities in China 2022-2028
- SPI based on firmware library
- [cloud native topic -48]:kubesphere cloud Governance - operation - overview of multi tenant concept
- (Video + graphics and text) introduction to machine learning series - Chapter 4 naive Bayes
- [leetcode] interview question 17.08 Circus tower
- P3371 [template] single source shortest path (weakened version)
猜你喜欢

2022 system integration project management engineer examination knowledge points: software development model

Ningde times and BYD have refuted rumors one after another. Why does someone always want to harm domestic brands?
![[error record] configure NDK header file path in Visual Studio (three header file paths of NDK | ASM header file path selection related to CPU architecture)](/img/44/aa4963d07d046deb2bc76eb59f8ff7.jpg)
[error record] configure NDK header file path in Visual Studio (three header file paths of NDK | ASM header file path selection related to CPU architecture)
![[PHP basics] session basic knowledge, application case code and attack and defense](/img/f5/713d7044a693ef23e3fbb1ff9bc9f4.jpg)
[PHP basics] session basic knowledge, application case code and attack and defense

Detailed explanation of the relationship between Zhongtai, wechat and DDD
![Several ways to set up a blog locally [attach relevant software download links]](/img/2f/51a09d9ef71065319ed90306517854.jpg)
Several ways to set up a blog locally [attach relevant software download links]

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

Joint examination of six provinces 2017
![[cloud native topic -48]:kubesphere cloud Governance - operation - overview of multi tenant concept](/img/b4/961b3b44e9ecbfd4bddd04318b663a.jpg)
[cloud native topic -48]:kubesphere cloud Governance - operation - overview of multi tenant concept

The FISCO bcos console calls the contract and reports an error does not exist
随机推荐
Stock price forecast
AI Challenger 2018 text mining competition related solutions and code summary
Distributed transaction -- middleware of TCC -- selection / comparison
Selenium library 4.5.0 keyword explanation (I)
MySQL winter vacation self-study 2022 12 (2)
【leetcode】300. Longest increasing subsequence (dynamic programming, dichotomy)
Make small tip
Understanding of Radix
不得不会的Oracle数据库知识点(三)
What does redis do? Redis often practices grammar every day
From functional testing to automated testing, how did I successfully transform my salary to 15K +?
Is the securities account opened by Caicai for individuals safe? Is there a routine
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
功能:将主函数中输入的字符串反序存放。例如:输入字符串“abcdefg”,则应输出“gfedcba”。
【leetcode】374. Guess the size of the number
What insurance products should be bought for the elderly?
Why use get/set instead of exposing properties
8. Go implementation of string conversion integer (ATOI) and leetcode
[C language] break and continue in switch statement
Report on the construction and development mode and investment mode of sponge cities in China 2022-2028