intmain() { int a = 1; int b = 1; int c; int i = 0; int n = 0; scanf("%d", &n); // 第几项 for (i = 3; i <= n; i++) { c = a + b; a = b; b = c; } printf("%d", b); return0; }
------------------------------- intmain() { int a = 1, b = 1, c = 0; for (int i = 1; i <= 40; i++) { printf("%12d\n", a); c = a + b; a = b; b = c; } return0; }
方法二
每次输出两项
1 2 3 4 5 6 7 8 9 10 11
intmain() { int a = 1, b = 1, c = 0; for (int i = 1; i <= 20; i++) { printf("%14d\n%14d\n", a, b); a = a + b; b = a + b; } return0; }