C monkey eat peach

Source: Internet
Author: User

C monkey eat peach
The monkey has a peach problem. On the first day, the monkey picked several peaches and immediately ate half of them. They were so addicted that they ate another one. The next morning, I ate another half of the remaining peaches, and I ate another one. In the future, the remaining half of the previous day will be eaten every day, and one peach will be left when you want to eat it again on the morning of the seventh day. How many peaches can be picked on the first day. Code implementation:

# Include <stdio. h> int sum_peach (const int n, int sum) {int I = 0; for (I = n; I> 0; I --) {sum = 2 * sum + 1;} return sum;} int main () {int n = 0; int sum = 0; printf ("Enter the number of days :"); scanf ("% d", & n); sum = sum_peach (n, sum); printf ("% d \ n", sum); return 0 ;}

 


Related Article

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.