Skip to content

Instantly share code, notes, and snippets.

@EteimZ
Created January 9, 2023 22:44
Show Gist options
  • Select an option

  • Save EteimZ/cff2fff28216caef1ae80458cbfd461e to your computer and use it in GitHub Desktop.

Select an option

Save EteimZ/cff2fff28216caef1ae80458cbfd461e to your computer and use it in GitHub Desktop.
Fib implemented with the static keyword in C++
#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