用数组处理斐波那契数列问题.c

Fibonacci series : The series from start to question 3rd, each equal to the sum of the first two.This code will use the methods of the array to the problem of dealing with the Fibonacci sequence. The following code :

//  date:2020/3/5
//  author:xiezhg5
#include <stdio.h>
#define N 100                  //为方便可直接修改N值 
int main(void)
{
	int i;
	int f[N]={1,1};           //定义一个有N个元素的数组,并为a[0]和a[1]赋初值1 
	for(i=2;i<N;i++)          //从求解a[2]开始 
	f[i]=f[i-2]+f[i-1];        //Fibonacci数列规律 
	for(i=0;i<N;i++)          //将N个元素全部输出 
	{
		if(i%10==0) printf("\n");   //i是控制行数的变量,每10个数换一行 
		printf("%5d ",f[i]);       //输出数列前100项的值 
	}
	return 0;
}
发布了30 篇原创文章 · 获赞 10 · 访问量 278

猜你喜欢

转载自blog.csdn.net/qq_45645641/article/details/104676393