#include <iostream>
#include <cstdlib>
using namespace std;
int main()
{
int s=1,i; //s为桃子总数,i是天数
//看似是第十天剩下了1个,事实上是第九天后剩下了1个
for(i=1;i<=9;i++)
{
s = (s+1)*2;
}
cout<<"s="<<s<<endl;
system("pause");
return 0;
}
输出结果为1534
本文通过一个C++程序解决了一个经典的数学问题——桃子问题。程序采用逆向思维,从最后一天剩余的桃子数量出发,通过迭代计算得出最初桃子的总数。输出结果为1534,展示了一种解决此类问题的有效方法。
660

被折叠的 条评论
为什么被折叠?



