喝汽水问题

时间:2023-02-11 00:54:20

一瓶汽水1元,两个空瓶可以兑换一瓶汽水

#include<stdio.h>

int main() {
int money = 0;
int drink = 0;
int empty = 0;
scanf_s("%d", &money);
//花钱买的
drink = money;
empty = money;
//用空瓶换的
while (empty >= 2) {
drink = empty / 2 + drink;
empty = empty / 2 + empty % 2;
}
printf("花费%d元最多可以喝到%d瓶", money,drink);
return 0;
}