例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("\n");
	return 0; 
 } 

结果

1 1 2 3 5 8 13 21 34 55

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


分析

重点:次数循环for

posted on 2019-04-06 09:47  凯*凯  阅读(218)  评论(0编辑  收藏  举报

导航