Easy Tutorial
❮ C Function Strcmp C Function Vfprintf ❯

Monkey Eating Peaches Problem

C Language Classic 100 Examples

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 one more; this pattern continued every day. On 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<stdio.h>

int main()
{
    int i = 1;
    int j = 1;
    for (j = 10; j > 1; j--)
    {
        i++;
        i = 2 * i;
    }
    printf("On the first day, he picked %d peaches.", i);
}

The above example outputs:

On the first day, he picked 1534 peaches.

C Language Classic 100 Examples

❮ C Function Strcmp C Function Vfprintf ❯