计算斐波那契图

时间:2016-03-11 19:04:45

标签: c# console console-application

我正在为我的cs课程编写一个程序,这就是我想出来的。问题是我的婴儿和成人专栏都已切换。我知道我可以在显示它们时切换它们,但这并不能帮助我理解它是如何工作的。也许我只是不理解它背后的逻辑......

有一张照片可以显示它的外观。

        int adult = 1;
        int baby = 0;
        int total = 1;
        int month = 0;


        WriteLine("Table of rabbit population, in pairs.\n");
        WriteLine("Month\tAdults\tBabies\tTotal");


        do
        {
            month++;

            int temp = adult;                

            adult = baby;
            baby = temp + adult;


            total = adult + baby;

            WriteLine($"{month}\t{adult}\t{baby}\t{total}");
        } while (total < 500);

        WriteLine("\n\n");

        WriteLine($"Will run out of cages in month {month}\n\n");

        Write("Press any key to continue ... ");

This is what the program is suppose to look like.

1 个答案:

答案 0 :(得分:0)

据我所知,他们已经切换了#34;正如你所说,因为你这样做:

int temp = adult;                

adult = baby;
baby = temp + adult;

您正在创建一个临时变量并为其分配adult的值,然后您将baby的值分配给adult变量。切换。