斐波那契数列输出的C语言实现
1.流程图
2.代码实现
#include <stdio.h>#define num1 0//第一项#define num2 1//第二项int Fibonacci_Sequence(int num_n1, int num_n2, int times_0,int times_already)//num_1为第n-2位数,int num_n2为第n-1位数,int num_n3为第n位{int num_n3 = num_n1 + num_n2;//第n位等于前两位之和printf(",%d", num_n3);//打印输出times_already ++;//已打印项数加一if (times_already < times_0)//若已打印项数小于总项数,再次执行函数{Fibonacci_Sequence(num_n2, num_n3, times_0, times_already);}return 0;}int main() {printf("typein amount of numbers:");int amount = 0;//总项数为amountscanf("%d", &amount);if (amount == 1)//项数为1printf("Fibonacci_Sequence:%d", num1);if (amount == 2)//项数为2printf("Fibonacci_Sequence:%d,%d", num1, num2);if (amount >= 3)/*项数大于2*/{printf("Fibonacci_Sequence:%d,%d", num1, num2);Fibonacci_Sequence(0, 1, amount, 2);}//总项数为amount,已打印项数:2return 0;}