Peach eating for monkeys

Source: Internet
Author: User
Adopt reverse thinking:
/* The Monkey eats peaches. On the first day, the monkey picked up a few peaches, and immediately eats half of them, and then eats another one. In the morning of the next day, I eat half of the remaining half and one more. In the future, I will eat the remaining half of the day before yesterday and only the last peach in the morning of 10th. I picked a few peaches on the first day. */# Include <stdio. h> int main () {int sum; // total peach count int day = 9; // Number of days int temp = 1; while (day! = 0) {// 1 peach in 10th days, then the number of peaches in 9th days = (the remaining number of peaches in 10th days + 1) 2 times after temp = 2 * (temp + 1); // The number of peaches on the first day is 2 times the day after the number on the first day plus the number on the second day --;} sum = temp; printf ("% d \ n", sum); // The answer is 1534 peaches return 0 ;}

Peach eating for monkeys

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.