/** * A probram to calculate fibonacci numbers and make a nice looking table of them * @authod gtowell * Created: Feb 2021 */ #include #define HEADER "%6s%9s%9s%9s%9s\n" #define DATA "%6d%9d%9d%9d%9.5f\n" /** * DO the fibonacci work * @param maxVal -- the largest fibonacci number to calculate */ void doTheFibb(int maxVal) { int f1 = 1; int f2 = 1; int n = 2; printf(HEADER, "", "fibb", "fibb", "fibb", "golden"); printf(HEADER, "index", "n -2", "n -1", "n", "mean"); while (f1 < maxVal) { n++; int f3 = f2 + f1; printf(DATA, n, f1, f2, f3, (float)f3 / f2); f1 = f2; f2 = f3; } } int main(int argc, char const *argv[]) { doTheFibb(100000); return 0; }