分析:
①设x1为前一天桃子数,设x2为第二天桃子数,则
x2=x1/2-1, x1=(x2+1)*2
x3=x2/2-1, x2=(x3+1)*2
以此类推: x前=(x后+1)*2 ;
②从第10天可以类推到第1天,是一个循环过程。程序如下:
#include
using namespace std;
int main( )
{
int day,x1,x2;
cin>>day;
x2=1;
while(day>0)
{
x1=(x2+1)*2; /*第一天的桃子数是第2天桃子数加1后的2倍*/
x2=x1;
day--;
}
cout<<"the total is "<