/* Program to print Fibonacci numbers. Requests the two starting values and the amount to compute. */ #include void print_Fibonacci (void); int F1, F2, num; /* Two starting values, and the number to calculate */ main () { printf("\tFibonacci numbers\nEnter the two Fibonacci starting values: "); scanf("%d %d", &F1, &F2); printf("Enter the number of values to compute: "); scanf("%d", &num); print_Fibonacci(); } void print_Fibonacci (void) { /* Prints num Fibonacci numbers, starting with F1 & F2 */ int nextfib; /* the next number in the sequence */ /* Let num be the number still to print. */ while (num > 0) { /* more to print */ nextfib = F1 + F2; /* compute next */ printf("%d\n", nextfib); /* print */ F1 = F2; F2 = nextfib; /* 'slide' the numbers down one, ready for the next loop iteration. */ num--; /* one fewer number still to print */ } }