C Exercise 80
100 Classic C Language Examples
**Problem:** There is a pile of peaches on a beach, and five monkeys come to divide them. The first monkey divides the pile into five equal parts with one left over, throws the extra one into the sea, and takes one part. The second monkey divides the remaining peaches into five equal parts again, again with one left over, throws the extra one into the sea, and takes one part; the third, fourth, and fifth monkeys all do the same. What is the minimum number of peaches originally on the beach?
**Analysis:** None.
Program source code:
Example
// Created by www.runoob.com on 15/11/9.
// Copyright (c) 2015 Runoob Tutorial. All rights reserved.
//
#include
<
stdio.h
int
main
(
)
{
int
n
=
0;
// n represents the initial number of peaches
int
i
,
count
;
int
found
=
0
;
while
(
!
found
)
{
n
+=
1
;
// Assume the initial number of peaches
count
=
n
;
for
(
i
=
0
;
i
<
5
;
i
++
)
{
if
(
(
count
1
)
%
5
==
0
)
{
count
=
(
count
1
)
/
5
4
;
}
else
{
break
;
}
}
if
(
i
==
5
)
{
found
=
1
;
}
}
printf
(
"
There are at least %d peaches.
\
n
"
,
n
)
;
return
0
;
}
The above example produces the following output:
3121