斐波那契数列:1 1 2 3 5 8 13 21 ...
规律:
从第三个数开始,第n个数为前两数之和
#include <stdio.h> int main() { int n = 0; scanf("%d", &n); int a = 1; int b = 1; int c = 1; while (n >= 3) { c = a + b; a = b; b = c; n--; } printf("第n个斐波那契数:%d\n", c); return 0; }
注意循环结束条件,和变量c的初始值。
标签:练习题,契数,打印,int,个斐波,两数 From: https://www.cnblogs.com/xiaowanglong/p/17901092.html