当前位置:网站首页>C语言经典例题-求最少数量钞票
C语言经典例题-求最少数量钞票
2022-07-23 10:47:00 【Blue_lan18】
编写一个程序,要求用户输入一个美金数量,然后显示出如何用最少的20美元、10美元、5美元和1美元来付款:
# include <stdio.h>
int main()
{
int amount;
int twentyDollars = 0;//定义20美元钞票数量
int tenDollars = 0;
int fiveDollars = 0;
int oneDollars = 0;
printf("Enter an dollar amount: ");
scanf("%d", &amount);
twentyDollars = amount / 20;
tenDollars = (amount - twentyDollars *20) / 10;//计算10美元钞票数量
fiveDollars = (amount - twentyDollars *20 - tenDollars *10) / 5;
oneDollars = amount - twentyDollars *20 - tenDollars *10- fiveDollars;
printf("$20 bills: %d\n", twentyDollars);
printf("$10 bills: %d\n", tenDollars);
printf("$5 bills: %d\n", fiveDollars);
printf("$1 bills: %d\n", oneDollars);
return 0;
}
边栏推荐
猜你喜欢

Matlab simulation of Turbo code error rate performance

Analysis of data governance

Exploration and practice of Ali multimodal knowledge atlas

老照片上色——DeOldify快速上手

xlswriter - excel导出

select......for update 语句的功能是什么? 会锁表还是锁行?

The best time to buy and sell stocks

VSCode 更新后与tab相关快捷键无法使用

Xlswriter - Excel export

Idea five free plug-ins to improve efficiency
随机推荐
上小学之前要学会的本领指引
7.13WEB安全作业
【启发式分治】启发式合并的逆思想
BGP basic configuration
Skills to learn before going to primary school
深入理解CAS (自旋锁)
安全合理用电 收获清凉一“夏”
JSD-2204-会话管理-过滤器-Day19
【OpenCV 例程200篇】225. 特征提取之傅里叶描述子
uniapp实现横向点击滑动菜单
MapReduce InputFormat之FileInputFormat
Smart headline: smart clothing forum will be held on August 4, and the whole house smart sales will exceed 10billion in 2022
MySQL执行顺序
Activity的启动流程
基于双目相机拍摄图像的深度信息提取和目标测距matlab仿真
Part V Druid data source introduction
Start process of activity
VSCode 更新後與tab相關快捷鍵無法使用
581. Shortest unordered continuous subarray
Byte stream & character stream of IO stream