斐波那契额数列

#include <stdio.h>

Fib(int n)		//n代表第几个数
{
	if (n == 1 || n == 2) return 1;
	else return Fib(n - 1) + Fib(n - 2);
}
fib(int n)		//列出前n个数
{
	int fib1 = 1, fib2 = 1;
	int fib;
	printf("%12d%12d", fib1, fib2);
	for (int i = 3; i <= n; i++)
	{
		fib = fib1 + fib2;
		printf("%12d", fib);
		fib1 = fib2;
		fib2 = fib;
		if (i % 4 == 0)printf("\n");
	}
}
int main()
{
	int n;
	printf("please input n:");
	scanf_s("%d", &n);
	//printf("%d", Fib(n));	//输出第n个数
	fib(n);
	return 0;
}

posted @ 2023-04-17 21:24  258333  阅读(13)  评论(0编辑  收藏  举报