#include<stdio.h>//兔子生崽问题 #define N 12 void Fibonacci(int f[], int n); int main() { int f[N], i; Fibonacci(f, N); printf("\nTotal = %d\n", f[N - 1]); return 0; } void Fibonacci(int f[], int n)//计算并打印Fibonacci数列的前n项 { int i; f[0] = 1; f[1] = 2; for (i = 2; i < n; i++) { f[i] = f[i - 1] + f[i - 2]; } for (i = 0; i < N; i++) { printf("%-4d", f[i]); } }
C语言—兔子生崽问题(斐波那契数列)
于 2024-08-11 16:34:44 首次发布