C语言:20元喝汽水问题

来源:互联网 发布:数据库系统分为 编辑:程序博客网 时间:2024/04/28 21:45

环境: 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;}
0 0
原创粉丝点击