Created
January 9, 2023 22:44
-
-
Save EteimZ/cff2fff28216caef1ae80458cbfd461e to your computer and use it in GitHub Desktop.
Fib implemented with the static keyword in C++
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; | |
| void fib(){ | |
| static int a = 0; | |
| static int b = 1; | |
| static int c; | |
| cout << a << endl; | |
| c = a; | |
| a = b; | |
| b = b + c; | |
| } | |
| int main() { | |
| for (int i = 0; i<10; i++) | |
| fib(); | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment