1) non-recursive
Define first f1,f2 Give the values of the first two terms of Fibonacci series , Redefinition f3 Save the sum of the first two items , Which is the value of the next item , Constantly changing assignments in recycling , Finally, find out the n term .
#include<stdio.h> #include<stdlib.h> int fabonacci(int n) { int f1 = 1; int f2
= 1; int i = 0, f3 = 1; for (i = 3; i <= n; i++) { f3 = f1 + f2; f1 = f2; f2 =
f3; } return f3; } int main() { int a = 0; printf(" Please enter a Value of :"); scanf("%d", &a);
printf("%d\n", fabonacci(a)); system("pause"); return 0; }
2) recursion
Find out that the termination condition of recursion is that the values of the first and second terms are equal to 1, Then according to the formula f(n)=f(n-1)+f(n-2) We can get the conclusion that n term .
#include<stdio.h> #include<stdlib.h> int facibo(int n) { if ((n == 1) || (n ==
2)) { return 1; } else { return facibo(n - 1) + facibo(n - 2); } return 0; } int
main() { int a = 0; printf(" Please enter a Value of :"); scanf("%d", &a); printf("%d\n", facibo(a)
); system("pause"); return 0; }

Technology
©2019-2020 Toolsou All rights reserved,
( Essence )2020 year 6 month 26 day C# Class library Log help class python primitive -- lock LockPowerShell Use in WebClient Download the file and get the download progress python Dynamic programming for single source shortest path ( Essence )2020 year 7 month 21 day ASP.NET Core Use of global filters keras from dataframe Read data and enhance the data for training ( classification + division )npm ERR! code ELIFECYCLE npm ERR! errno 1 npm ERR! test_vue_0613@1.0.0 dev: Solutions to errors element-ui+vue-treeselect Verification of drop down box ( Essence )2020 year 7 month 15 day Wechat applet import and include difference el-select Get selected label value