Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdbool.h>
- unsigned fibonacci(bool reset) {
- static unsigned n1 = 0;
- static unsigned n2 = 1;
- if(reset) {
- n1 = 0;
- n2 = 1;
- }
- unsigned retval = n1;
- n2 += n1;
- n1 = n2 - n1;
- return retval;
- }
- int main() {
- for(size_t i = 0; i < 20; ++i) {
- if(i == 10) printf("\n-- reiniciando --\n");
- printf("%u\n", fibonacci(i == 10));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement