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

100 Classic C Language Examples 100 Classic C Language Examples

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

<

stdio.h

int

main

(

)

{

int

i

=

1

;

int

j

=

1

;

for

(

j

=

10

;

j

1

;

j

--

)

{

i

++;

i

=

2

i

;

}

printf

(

"

%d peaches were picked on the first day.

"

,

i

)

;

}

The output of the above example is:

第一天摘了 1534 个桃子。

100 Classic C Language Examples 100 Classic C Language Examples