Monkey eating peach problem

C++ Examples

A little monkey picked many peaches one day. On the first day, it ate half, then couldn't resist and ate one more. On the second day, it ate half, plus one more. Every day after that, it ate in the same way. By the 10th day, the little monkey found there was only one peach left. The question is: how many peaches did the little monkey pick in total on the first day?

Example

#include <iostream> using namespace std; int main() { int x, y, n; for (x=1, n=0; n<9; y=(x+1)*2, x=y, n++); cout<<"The total number of peaches picked on the first day is"<<x<<endl; return 0; }

The output of the above example is:

第一天共摘的桃子数量为 1534

C++ Examples

other extensions