Write a program to calculate the Fibonacci sequence• The i-th element of the Fibonacci sequence is defined as follows.公式请看图 Ex)011235813
Fibonacci sequence• Input 1, input another numberto calculate the Fibonacci sequence• Input 2, show the Fibonacci sequence • Input 3, initialization• Input 4, terminate the program
c语言。
- 写回答
- 好问题 0 提建议
- 追加酬金
- 关注问题
- 邀请回答
-
4条回答 默认 最新
- 纵横车 2015-10-17 05:02关注
void PrintMenu() { printf("*************\n"); printf("1. Calculate\n"); printf("2. Show it!\n"); printf("3. Initialize\n"); printf("4. Quit\n"); printf("*************\n"); printf("Input : "); } int main() { char a; int b = 0; int i; int Fx = 1; int Fxx = 0; while(true) { PrintMenu(); a = getchar(); getchar(); switch(a) { case '1': printf("Input the number : "); scanf("%d",&b); getchar(); break; case '2': for(i=0;i<b;i++) { if(i == 0) printf("%d ",Fxx); else if(i == 1) printf("%d ",Fx); else { printf("%d ",Fx+Fxx); int temp = Fx; Fx += Fxx; Fxx = temp; } } printf("\n"); Fx = 1; Fxx = 0; break; case '3': b = 0; break; case '4': return 0; } } return 0; }
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报
悬赏问题
- ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
- ¥15 cmd cl 0x000007b
- ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
- ¥500 火焰左右视图、视差(基于双目相机)
- ¥100 set_link_state
- ¥15 虚幻5 UE美术毛发渲染
- ¥15 CVRP 图论 物流运输优化
- ¥15 Tableau online 嵌入ppt失败
- ¥100 支付宝网页转账系统不识别账号
- ¥15 基于单片机的靶位控制系统