Skip to content

Instantly share code, notes, and snippets.

@jammy-dodgers
Created September 20, 2017 10:32
Show Gist options
  • Save jammy-dodgers/521e0e41ad8e042d19412a39484a2dcb to your computer and use it in GitHub Desktop.
Save jammy-dodgers/521e0e41ad8e042d19412a39484a2dcb to your computer and use it in GitHub Desktop.
struct Fibonacci
{
int pos;
int current;
int n1;
int n2;
};
struct Fibonacci new_Fibonacci()
{
struct Fibonacci gener_temp_init_var;
gener_temp_init_var.pos = 0;
return gener_temp_init_var;
}
int Fibonacci_has_next(struct Fibonacci *vars)
{
switch (vars->pos)
{
case 0:
{
vars->n1 = 0;
vars->n2 = 1;
while (vars->n1 < 10000)
{
int tmp = vars->n1;
vars->n1 = vars->n2;
vars->n2 = tmp + vars->n2;
vars->current = (tmp);
vars->pos = 1;
return 1;
case 1:;
}
};
return 0;
}
return 0;
}
int main()
{
struct Fibonacci f;
f = new_Fibonacci();
{
struct Fibonacci foreach_loop_var;
foreach_loop_var = f;
while (Fibonacci_has_next(&foreach_loop_var))
{
int i = foreach_loop_var.current;
{
printf("%d\n", i);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment