当前位置:网站首页>功能:求出菲波那契数列的前一项与后一项之比的极限的 近似值。例如:当误差为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:放假快乐放假快乐放假快乐放假快乐放假快乐放假快乐放假快乐放假快乐放假快乐放假快乐放假快乐放假快乐
边栏推荐
- 打印菱形图案
- Kubedl hostnetwork: accelerating the efficiency of distributed training communication
- Suggestions for improving code quality
- From functools import reduce -- see the use of reduce function from typical examples
- Is user authentication really simple
- What is the Valentine's Day gift given by the operator to the product?
- Briefly understand the operation mode of developing NFT platform
- It is forbidden to splice SQL in code
- Make small tip
- I would like to ask how the top ten securities firms open accounts? Is it safe to open an account online?
猜你喜欢
Idea a method for starting multiple instances of a service
Cannot build artifact 'test Web: War expanded' because it is included into a circular depend solution
[PHP basics] cookie basics, application case code and attack and defense
Att & CK actual combat series - red team actual combat - V
[PHP basics] session basic knowledge, application case code and attack and defense
A Kuan food rushed to the Shenzhen Stock Exchange: with annual sales of 1.1 billion, Hillhouse and Maotai CCB are shareholders
The difference between objects and objects
Axure resources and prototype tool Axure RP 9 download
Report on the construction and development mode and investment mode of sponge cities in China 2022-2028
It is the most difficult to teach AI to play iron fist frame by frame. Now arcade game lovers have something
随机推荐
Unity elementary case notes of angry birds Siki college 1-6
网上的低佣金链接安全吗?招商证券怎么开户?
Global and Chinese market of underwater bags 2022-2028: Research Report on technology, participants, trends, market size and share
Report on prospects and future investment recommendations of China's assisted reproductive industry, 2022-2028 Edition
Is user authentication really simple
Generic
[complimentary ppt] kubemeet Chengdu review: make the delivery and management of cloud native applications easier!
Make small tip
功能:将主函数中输入的字符串反序存放。例如:输入字符串“abcdefg”,则应输出“gfedcba”。
[PHP basics] session basic knowledge, application case code and attack and defense
Pytest unit test framework: simple and easy to use parameterization and multiple operation modes
What is the Valentine's Day gift given by the operator to the product?
Ningde times and BYD have refuted rumors one after another. Why does someone always want to harm domestic brands?
[about text classification trick] things you don't know
HR disgusted interview behavior
Global and Chinese markets for instant saliva testing devices 2022-2028: Research Report on technology, participants, trends, market size and share
Makefile judge custom variables
Ningde times and BYD have refuted rumors one after another. Why does someone always want to harm domestic brands?
Selenium library 4.5.0 keyword explanation (III)
Joint examination of six provinces 2017