喝汽水,1瓶汽水1元,2个空瓶可以换一瓶汽水,给20元,可以多少汽水(编程实现)。
0.5
20/0.5 = 40-1 = 39
#include
#include
int main()
{
int money = 0;
int total = 0;
int empty = 0;
scanf("%d", &money);
//买回来的汽水喝掉
if (money == 0)
total = 0;
else
total = 2 * money - 1;
//total = money;
//empty = money;
换回来的汽水
//while (empty>=2)
//{
// total += empty / 2;
// empty = empty / 2 + empty % 2;
//}
printf("total = %d\n", total);
return 0;
}
void print(int arr[], int sz)
{
int i = 0;
for (i = 0; i < sz; i++)
{
printf("%d ", arr[i]);
}
printf("\n");
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)