baybaye 2015-10-17 04:20 采纳率: 70%
浏览 1520
已采纳

c语言。

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图片说明图片说明

  • 写回答

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;
    
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥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 基于单片机的靶位控制系统