当前位置:网站首页>喝汽水,1瓶汽水1元,2个空瓶可以换一瓶汽水,给20元,可以多少汽水
喝汽水,1瓶汽水1元,2个空瓶可以换一瓶汽水,给20元,可以多少汽水
2020-11-08 12:56:00 【osc_51airx3z】
第一种方法
#include<stdio.h>
#include<Windows.h>
#pragma warning(disable:4996)
int Qishui(int n)
{
int total = 0;
total += n;
for (; n >= 2;n=n/2+n%2)
{
total += n / 2;
}
return total;
}
int main()
{
int money = 0;
printf("你有多少钱:");
scanf_s("%d", &money);
int ret = Qishui(money);
printf("可以买%d瓶汽水\n", ret);
system("pause");
return 0;
}
第二种方法
#include<stdio.h>
#include<Windows.h>
#pragma warning(disable:4996)
int Qishui(int money)
{
int total = money;
int empty = money;
while (empty > 1)
{
total += empty / 2;
empty = empty / 2 + empty % 2;
}
return total;
}
int main()
{
int money = 0;
printf("你有多少钱:");
scanf_s("%d", &money);
int ret = Qishui(money);
printf("可以买%d瓶汽水\n", ret);
system("pause");
return 0;
}
版权声明
本文为[osc_51airx3z]所创,转载请带上原文链接,感谢
https://my.oschina.net/u/4263556/blog/4708158
边栏推荐
- Automatically generate RSS feeds for docsify
- Top 5 Chinese cloud manufacturers in 2018: Alibaba cloud, Tencent cloud, AWS, telecom, Unicom
- C language I blog assignment 03
- Research on WLAN direct connection (peer-to-peer connection or P2P) and cross platform research of IOS
- Windows10关机问题----只有“睡眠”、“更新并重启”、“更新并关机”,但是又不想更新,解决办法
- It's worth seeing! EMR elastic low cost offline big data analysis best practice (with network disk link)
- Flink从入门到真香(10、Sink数据输出-Elasticsearch)
- 来自朋友最近阿里、腾讯、美团等P7级Python开发岗位面试题
- Where is the new target market? What is the anchored product? |Ten questions 2021 Chinese enterprise service
- 2018中国云厂商TOP5:阿里云、腾讯云、AWS、电信、联通 ...
猜你喜欢
Automatically generate RSS feeds for docsify
Ali tear off the e-commerce label
Rust: performance test criteria Library
C language I blog assignment 03
Win10 Terminal + WSL 2 安装配置指南,精致开发体验
Bccoin tells you: what is the most reliable investment project at the end of the year!
android基础-CheckBox(复选框)
Hematemesis! Alibaba Android Development Manual! (Internet disk link attached)
nat转换的ip跟端口ip不相同的解决方法
Tight supply! Apple's iPhone 12 power chip capacity exposed
随机推荐
PMP experience sharing
Share the experience of passing the PMP examination
Ubuntu20.04下访问FTP服务器乱码问题+上传文件
Service architecture and transformation optimization process of e-commerce trading platform in mogujie (including ppt)
一个方案提升Flutter内存利用率
Shell uses. Net objects to send mail
一文读懂机器学习“数据中毒”
吐血整理!阿里巴巴 Android 开发手册!(附网盘链接)
Adobe media encoder / me 2021 software installation package (with installation tutorial)
华为云重大变革:Cloud&AI 升至华为第四大 BG ,火力全开
Don't look! Full interpretation of Alibaba cloud's original data lake system! (Internet disk link attached)
原创 | 数据资产确权浅议
Suitable for C / C + + novice learning some projects, do not give me to miss!
阿里教你深入浅出玩转物联网平台!(附网盘链接)
Win10 Terminal + WSL 2 安装配置指南,精致开发体验
Top 5 Chinese cloud manufacturers in 2018: Alibaba cloud, Tencent cloud, AWS, telecom, Unicom
Istio流量管理--Ingress Gateway
后端程序员必备:分布式事务基础篇
笔试面试题目:盛水最多的容器
应届生年薪35w+ !倒挂老员工,互联网大厂薪资为何越来越高?