Fibonacci series
输出斐波那契数列前30个数,每行打印5个数
#include <stdio.h> #define MAX 30 int main() { int fib[MAX] = {1,1}; for (int i=2; i<MAX; i++) { fib[i] = fib[i-1] + fib[i-2]; } for (int i=0; i<MAX; i++) { printf("%8d", fib[i]); if ((i+1) % 5 == 0) printf(" "); } return 0; }
输出结果:
1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 1597 2584 4181 6765 10946 17711 28657 46368 75025 121393 196418 317811 514229 832040