方式一
for循环 (20位)
#define _CRT_SECURE_NO_WARNINGS 1#include<stdio.h>
int main()
{int n;int a[20]={1,1};for ( n = 1; n <20; n++){a[n]=a[n-2]+a[n-1];}for ( n = 0; n < 20; n++){if(n%5==0)printf("\n");printf("%12d ",a[n]);}return 0;
}
方式二
用递归法编程
#define _CRT_SECURE_NO_WARNINGS 1#include<stdio.h>
long Fib(int n);
int main()
{int n,i,x;printf("Input n:");scanf("%d",&n);for ( i = 1; i <=n; i++){x=Fib(i);printf("Fi(%d) = %d\n",i,x);}return 0;
}
long Fib(int n)
{if (n == 0) return 0;else if (n ==1) return 1;else return (Fib(n-1)+Fib(n-2));return 0;
}