Title: The monkey picked a few peaches on the first day, ate half of it immediately, and ate one more. The next morning he ate half of the remaining peaches and ate one more. Every morning after eating the day before the rest of the peach half of the zero one. When I wanted to eat it on the 10th morning, I found that there was only one peach left. Write a program to find out how many peaches were picked on the first day.
This program first to find out the relationship between the variables, that is, the number of peaches and days of the relationship between the two, according to the topic: eat every day the day has a half of the peaches and one more!
Now we begin to think about this question : Set the i=1,2,3 (,...,) the total number of Peaches is ni, the first day the total number of Peaches is N1, the next day the total number of Peaches is n2,......
It is not difficult to find N (i+1) and NI satisfies the following formula: Ni=2n (i+1) +1, thinking here, basically the program comes out, or the idea of recursion:
The results of the operation are as follows:
Thanks for reading, hope to solve your doubts help!
The monkey eats the Peach