Mega Code Archive

 
Categories / C / Development
 

Output Fibonacci numbers

#include <stdio.h> #define LIMIT 40 int main(void) { long x0 = 0; long x1 = 1; long y = 0; long z = 0; printf("%7s%19s%29s\n%7s%19s%29s\n%7s%19s%29s\n", " ", "Fibonacci", "Fibonacci", " n", " number", " quotient", " -", "---------", "---------"); printf("%7d%19d\n%7d%19d\n", 0, 0, 1, 1); for(y = 2; y <= LIMIT; ++y) { z = x1; x1 += x0; x0 = z; printf("%7ld%19ld%29.16f\n", y, x1, (double)x1/x0); } return 0; }