每瓶汽水一元,两个空瓶子可以换一瓶汽水,现在有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; }