2
喝汽水--C语言_wx634979de429d2的技术博客_51CTO博客
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.
喝汽水--C语言
精选 原创问题:喝汽水,1瓶汽水1元,2个空瓶可以换一瓶汽水,给20元,可以多少汽水?
1.20元肯定可以喝20瓶
2.2个空瓶可以换一瓶汽水,则剩下瓶子数量:empty/2+empty%2
empty/2:表示成功换汽水的瓶子
empty%2:表示不够换的瓶子
3.当瓶子大于1又可换,故是循环问题
方法1:代码如下
方法2:代码如下(从方法1可得出其为等差数列的运用money*2-1)
运行截图:
- 赞
- 收藏
- 评论
- 分享
- 举报
上一篇:神秘的“图”--数据结构
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK