当前位置:网站首页>功能:求出菲波那契数列的前一项与后一项之比的极限的 近似值。例如:当误差为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:放假快乐放假快乐放假快乐放假快乐放假快乐放假快乐放假快乐放假快乐放假快乐放假快乐放假快乐放假快乐
边栏推荐
- 打印菱形图案
- Reading notes on how programs run
- P1656 bombing Railway
- Solve the problem that the kaggle account registration does not display the verification code
- [BSP video tutorial] stm32h7 video tutorial phase 5: MDK topic, system introduction to MDK debugging, AC5, AC6 compilers, RTE development environment and the role of various configuration items (2022-
- Zipper table in data warehouse (compressed storage)
- Makefile judge custom variables
- [PHP basics] cookie basics, application case code and attack and defense
- Double efficiency. Six easy-to-use pychar plug-ins are recommended
- Att & CK actual combat series - red team actual combat - V
猜你喜欢

STM32 GPIO CSDN creative punch in

Idea set class header comments

Struct in linked list
![[CSDN Q & A] experience and suggestions](/img/db/dff3173dda24ca5740729b54a81153.jpg)
[CSDN Q & A] experience and suggestions

A Kuan food rushed to the Shenzhen Stock Exchange: with annual sales of 1.1 billion, Hillhouse and Maotai CCB are shareholders

Test the influence of influent swacth on the electromagnetic coil of quartz meter

It is forbidden to splice SQL in code
![[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)

Makefile judge custom variables

Interview script of Software Test Engineer
随机推荐
Recommendation of knowledge base management system
It is worthy of "Alibaba internal software test interview notes" from beginning to end, all of which are essence
Idea set class header comments
老姜的特点
国元证券开户是真的安全可靠吗
2022 Software Test Engineer skill list, please check
Global and Chinese market of glossometer 2022-2028: Research Report on technology, participants, trends, market size and share
网上的低佣金链接安全吗?招商证券怎么开户?
Entropy and full connection layer
[NLP] text classification still stays at Bert? Duality is too strong than learning framework
[complimentary ppt] kubemeet Chengdu review: make the delivery and management of cloud native applications easier!
功能:编写函数fun求s=1^k+2^k +3^k + ......+N^k的值, (1的K次方到N的K次方的累加和)。
Introduction to thread pool
What insurance products should be bought for the elderly?
What is the potential of pocket network, which is favored by well-known investors?
Arc 135 supplementary report
Regular expressions and text processors for shell programming
[cloud native topic -48]:kubesphere cloud Governance - operation - overview of multi tenant concept
Qtcharts notes (V) scatter diagram qscatterseries
Axure resources and prototype tool Axure RP 9 download