斐波那契数列中的问题
程序代码:
# include <stdio.h> int main(void) { int F1=1, F2=1, Fn, n; char c; printf("斐波那契数列,请输入n值: "); scanf("%d", &n); if (n == 1) printf("该数是1 "); else if (n == 2) printf("该数是1 "); else { for (int i=3; i<=n; ++i) { Fn=F1+F2; F1=F2; F2=Fn; } printf("该数是%d ", Fn); } printf("是否需要将前四十个数字列出?(Y/N) "); scanf("%c", &c);//无论是c=getchar(),还是这个,编译器都直接跳过了这一行,为什么? if (c == 'Y') { int F1=1, F2=1, Fn, n=40, i; printf("%5d%5d", 1, 1); for (i=3; i<=n; ++i) { Fn=F1+F2; F1=F2; F2=Fn; printf("%5d", Fn); if (n%5 == 0) printf(" "); } } else printf("All right "); return 0; }