#include #include int main(void) { int n, next, count; int previous = 0; /* Fibonacci 0 */ int current = 1; /* Fibonacci 1 */ printf("Calculate which Fibonacci number? "); scanf("%d",&n); /* before here, n has been set to the bound */ count = 2; while (count <= n) { next = previous + current; // i.e. 2 = 0 + 1 previous = current; current = next; // after: 2 + 1 count++; } printf("Fibonacci %d is %d\n", n, current); return EXIT_SUCCESS; }