例4-11 斐波那契数列输出

例4-11 斐波那契数列输出

1 1 2 3 5 8……
程序核心——for语句

程序

#include<stdio.h>
int main()
{
	int i,x1=1,x2=1,x;
	printf("%d %d ",x1,x2);
	for(i=1;i<=8;i++)
	{
		x=x1+x2;
		printf("%d ",x);
		x1=x2;
		x2=x;
	}
	printf("
");
	return 0; 
 } 

结果

1 1 2 3 5 8 13 21 34 55

--------------------------------
Process exited after 0.3538 seconds with return value 0
请按任意键继续. . .


分析

重点:次数循环for

原文地址:https://www.cnblogs.com/5236288kai/p/10660884.html