Skip to content

Instantly share code, notes, and snippets.

@kuvaldini
Created April 6, 2022 20:26
Show Gist options
  • Save kuvaldini/00f43e26dd0b464402436a8e44a4b918 to your computer and use it in GitHub Desktop.
Save kuvaldini/00f43e26dd0b464402436a8e44a4b918 to your computer and use it in GitHub Desktop.
#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