打印斐波那契数列

知识点:利用for循环输出斐波那契数列。

注意:先输出结果,再做下一步运算。

#include<stdio.h>
#include<windows.h>
#include<math.h>
void main()
{
	int f1 = 1, f2 = 1, f3, i;
	for (i = 0; i<10; i++)
	{
		f3 = f1 + f2;
                printf("%d", f3);
		f1 = f2;
		f2 = f3;
	}
	system("pause");
}

输出结果:

2 3 5 8 13 21 34 55 89 144 请按任意键继续...

猜你喜欢

转载自blog.csdn.net/Fairy_boyfriend/article/details/89400685