c_winter_2019/fib.c

31 lines
473 B
C
Raw Permalink Normal View History

2020-01-31 14:49:37 +01:00
#include <stdio.h>
int main(void) {
int fib;
printf("fib? fib! fib? ");
scanf("%d", &fib);
int current = 0;
int next = 1;
if (fib < 1) {
printf("Wait, wat?\n");
return 1;
}
if (fib == 1) {
printf("fib: %d\n", current);
return 0;
}
for (int i = 2; i < fib; ++i) {
int new = current + next;
current = next;
next = new;
}
printf("fib: %d\n", next);
return 0;
}