当前位置:网站首页>C语言经典习题之猴子吃桃问题
C语言经典习题之猴子吃桃问题
2022-07-24 04:18:00 【Serendipity_-】
猴子吃桃问题:
猴子第一天摘下若干个桃子,当即吃了一半,还不瘾,又多吃了一个,第二天早上又将剩下的桃子吃掉一半,又多吃了一个。以后每天早上都吃了前一天剩下的一半零一个。到第10天早上想再吃时,见只剩下一个桃子了。求第一天共摘了多少。
C程序代码如下:
/*猴子吃桃问题:猴子第一天摘下若干个桃子,当即吃了一半,还不瘾,又多吃了一个,第二天早上又将剩下的桃子吃掉一半,又多吃了一个。 以后每天早上都吃了前一天剩下的一半零一个。到第10天早上想再吃时,见只剩下一个桃子了。求第一天共摘了多少。 */
#include <stdio.h>
int main(int argc, char const *argv[])
{
int n = 1;
for (int i = 9; i > 0; i--)
{
n = (n + 1) * 2;
}
printf("%d ", n);
return 0;
}
/*数学方式全部列出: (1+1)×2=4(个) (4+1)×2=10(个) (10+1)×2=22(个) (22+1)×2=46(个) (46+1)×2=94(个) (94+1)×2=190(个) (190+1)×2=382(个) (382+1)×2=766(个) (766+1)×2=1534(个) 答:第一天共摘了1534个桃子。*/
运行结果如图:
边栏推荐
- Educational Codeforces Round 132 A - D
- Pat grade a 1041 be unique
- PostgreSQL source code learning (32) -- checkpoint ④ - core function createcheckpoint
- 训练赛《眼不见,心不烦,理不乱》题解
- 如何用STATA进行chowtest
- Ambire gas tank launches exclusive NFT launch
- Pat class a 1040 long symmetric string
- conda 常用命令
- Combinatorial number (number of prime factors of factorials, calculation of combinatorial number)
- Particle Designer:粒子效果制作器,生成plist文件并在工程中正常使用
猜你喜欢

Chapter III query processing of PostgreSQL Guide - Insider exploration
![[C language] program environment and preprocessing operation](/img/6c/245c20956a40fa37b780abbbcfcaeb.png)
[C language] program environment and preprocessing operation

Particle Designer:粒子效果制作器,生成plist文件并在工程中正常使用

PostgreSQL source code learning (32) -- checkpoint ④ - core function createcheckpoint

Iqoo 10 series attacks originos original system to enhance mobile phone experience

Analyze the real-time development method of Bank of London

Live classroom system 04 create service module

Will your NFT disappear? Dfinity provides the best solution for NFT storage

What is the product and expressiveness of 113700 Xingrui? Come and have a look

Function application of 4G transmission module
随机推荐
The second anniversary of opengauss' open source, cracking the pain point of database ecology
How does the trend chart of spot silver change?
(008) flask is OK if you have a hand -- database migration flask migrate
PostgreSQL source code learning (32) -- checkpoint ④ - core function createcheckpoint
(零八)Flask有手就行——数据库迁移Flask-Migrate
[untitled]
eCB接口,其实质也 MDSemodet
Pyth deinitialization averages on many machine decision boundaries, starting on the bus
Leetcode 204. count prime number (2022.07.23)
Redis sentinel mode, master node check script
Exploration of new mode of code free production
Energy principle and variational method note 11: shape function (a dimension reduction idea)
002_ Kubernetes installation configuration
[untitled]
Function application of 4G transmission module
[C language] program environment and preprocessing operation
"Wei Lai Cup" 2022 Niuke summer multi school training camp 1 (summary of some topics)
值为 0 流程,另一部分看括但不限于如下这题是
Leetcode (Sword finger offer) - 11. Minimum number of rotation array
BGP notes (II)