您的位置:首页 > 编程语言

喝汽水,1瓶汽水1元,2个空瓶可以换一瓶汽水,给20元,可以多少汽水。编程实现。

2017-11-12 13:00 537 查看
int main()
{
int _bottle = 0;//当空瓶为奇数个时,表示剩下的瓶子
int money = 20;
int count = 0;//总共的汽水数
int bottle=0;//空瓶数
if (money > 0)
{
count = money;
bottle = money;
}
while (bottle != 1)
{
if (bottle % 2 == 0)
{
count += bottle / 2;
bottle = bottle / 2;
}
else
{
count += bottle / 2;
_bottle = bottle % 2;
bottle = bottle / 2 + _bottle;
}
}
printf("%d\n", count);
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐