27 lines
555 B
C++
27 lines
555 B
C++
//猴子吃桃
|
|
|
|
#include <iostream>
|
|
using namespace std;
|
|
|
|
/*
|
|
int main() {
|
|
int peaches = 1; // 第10天剩下的桃子数
|
|
// 逆推从第10天到第1天
|
|
for (int day = 9; day >= 1; --day) {
|
|
peaches = (peaches + 1) * 2; // 每天的桃子数量是前一天的剩余加1再乘2
|
|
}
|
|
cout << "第1天摘的桃子数量是: " << peaches << endl;
|
|
return 0;
|
|
}
|
|
*/
|
|
|
|
int main(){
|
|
int x = 1,day = 9;
|
|
while (day > 0)
|
|
{
|
|
x = (x+1) * 2;
|
|
day--;
|
|
}
|
|
cout <<"共摘了"<<x<<"个桃子"<<endl;
|
|
return 0;
|
|
}
|