标签:c语言
每瓶汽水一元,两个空瓶子可以换一瓶汽水,现在有20元可以喝多少瓶汽水
#include<stdio.h> int main() { int money = 0; int bottle = 0; int drink = 0; printf("money="); scanf("%d", &money); if(money) { int tmp = 0; bottle = money ; drink = bottle; while (bottle) { drink = drink + bottle / 2;//喝的汽水数 tmp = bottle / 2; bottle = tmp + bottle % 2;//剩余瓶子数 if (1==tmp)//只剩下一个瓶子时不能交换汽水 break; } } printf("汽水=%d", drink); system("pause"); return 0; }
本文出自 “无以伦比的暖阳” 博客,请务必保留此出处http://10797127.blog.51cto.com/10787127/1713445
标签:c语言
原文地址:http://10797127.blog.51cto.com/10787127/1713445