作业帮 > 综合 > 作业

编写c语言程序 假定有 5 角、 1 角、 5 分、 2 分和 1 分共 5 种硬币,在 给顾客找硬币时,一般都会尽可能

来源:学生作业帮 编辑:作业帮 分类:综合作业 时间:2024/05/10 01:11:22
编写c语言程序 假定有 5 角、 1 角、 5 分、 2 分和 1 分共 5 种硬币,在 给顾客找硬币时,一般都会尽可能
#include
void main(){
int n;
printf("输入要找的硬币总数:");
scanf("%d",&n);

int five_cent = 0;//5角
five_cent = n/50;
n -= five_cent * 50;
int one_cent = 0;//1角
one_cent = n/10;
n -= one_cent * 10;
int five_penny = 0;//5分
five_penny = n/5;
n -= five_penny * 5;
int two_penny = 0;//2分
two_penny = n/2;
n -= two_penny * 2;
int one_penny = 0;//1分
one_penny = n;
printf("5角:%d\n",five_cent);
printf("1角:%d\n",one_cent);
printf("5分:%d\n",five_penny);
printf("2分:%d\n",two_penny);
printf("1分:%d\n",one_penny);
}