Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

Monkey and Peaches Problem

Monkey and Peaches Problem

C++ Example C++ Example

A little monkey picked many peaches one day. On the first day it ate half of them, then couldn't help eating one more; on the second day it ate half again, plus one more; and so on for each following day. On the 10th day, the little monkey found only one peach left. The question is: how many peaches did the little monkey pick 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 number of peaches picked on the first day is

"

<<

x

<<

endl

;

return

0

;

}

The output of the above example is:

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

C++ Example C++ Example