Easy Tutorial
❮ Cpp Strings Cpp Data Encapsulation ❯

Monkey Peach Problem

C++ Example

A little monkey picked a lot of peaches one day. On the first day, he ate half of them and couldn't resist eating one more; on the second day, he ate half again and then one more; this pattern continued every day. By the 10th day, the monkey found there was only one peach left. How many peaches did the monkey pick on the first day?

Example

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

The output of the above example is:

The total number of peaches picked on the first day is 1534

C++ Example

❮ Cpp Strings Cpp Data Encapsulation ❯