int peachCount = 1;
int total;
for(int day = 9;day >= 1;day--)
{
total = (peachCount + 1)*2
peachCount = total;
}
Console.WriteLine("猴子第一天摘得桃子数量为:"+peachCount);
首先,定义一个变量“peachCount”,为桃子剩余的数量,“total”为第几天时桃子一共的数量,我们已知最后一天所剩的桃子为1颗,假设第十天为x,第九天为y,所以,第九天桃子的数量为“y=(x+1)*2”,然后,利用“for”循环语句,我们可以从第九天开始计算,逆着推算出第一天摘得桃子数量。