Created
April 6, 2022 20:26
-
-
Save kuvaldini/00f43e26dd0b464402436a8e44a4b918 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
int main() { | |
int n; | |
cout << "Enter Fibonacci index: "; | |
cin >> n; | |
if(n <= 1){ | |
cout << n << endl; | |
} | |
int t1 = 0, t2 = 1, t = 0; | |
for (int i = 2; i < n; ++i) { | |
t = t1 + t2; | |
t1 = t2; | |
t2 = t; | |
} | |
cout << t << endl; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment