2

喝汽水--C语言_wx634979de429d2的技术博客_51CTO博客

 1 year ago
source link: https://blog.51cto.com/u_15830263/5885114
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

喝汽水--C语言

精选 原创

东西不是东西 2022-11-24 21:47:33 ©著作权

文章标签 等差数列 文章分类 C/C++ 编程语言 阅读数189

问题:喝汽水,1瓶汽水1元,2个空瓶可以换一瓶汽水,给20元,可以多少汽水?

1.20元肯定可以喝20瓶

2.2个空瓶可以换一瓶汽水,则剩下瓶子数量:empty/2+empty%2

empty/2:表示成功换汽水的瓶子

empty%2:表示不够换的瓶子

3.当瓶子大于1又可换,故是循环问题

方法1:代码如下

喝汽水--C语言_等差数列

方法2:代码如下(从方法1可得出其为等差数列的运用money*2-1)

喝汽水--C语言_等差数列_02

运行截图:

喝汽水--C语言_等差数列_03
  • 收藏
  • 评论
  • 分享
  • 举报

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK