环境: Windows 8,Visual Studio 2013
语言: C语言
实验要求: 现有一汽水站,2元一瓶汽水,每两个汽水瓶又可以换1瓶汽水,假如你有20元,现在问你能喝到多少瓶汽水
实验结果:
代码展示
#define _CRT_SECURE_NO_WARNINGS 10
#include<stdlib.h>
#include<stdlib.h>
int count_drink_water(int num)
{
int total = 20;
int bottles = 20;
while (bottles>1){
total += bottles / 2;
bottles = bottles / 2 + bottles % 2;
}
return total;
}
int main()
{
int total= count_drink_water(20);
printf("一共喝了%d瓶\n", total);
system("pause");
return 0;
}