单位给职工发工资为了保证不临时兑换零钱,且发放的总张数最少,要提前统计出给所有职工发工资所需的各种币值的张数,币值为100.50,20,10,5,2,1共七种币种 的c++代码
时间: 2024-06-03 22:08:51 浏览: 54
#include <stdio.h>
int main()
{
int salary, num_100, num_50, num_20, num_10, num_5, num_2, num_1;
printf("请输入职工工资:");
scanf("%d", &salary);
num_100 = salary / 100;
salary %= 100;
num_50 = salary / 50;
salary %= 50;
num_20 = salary / 20;
salary %= 20;
num_10 = salary / 10;
salary %= 10;
num_5 = salary / 5;
salary %= 5;
num_2 = salary / 2;
salary %= 2;
num_1 = salary;
printf("需要发放的各种币值的张数如下:\n");
printf("100元:%d张\n", num_100);
printf("50元:%d张\n", num_50);
printf("20元:%d张\n", num_20);
printf("10元:%d张\n", num_10);
printf("5元:%d张\n", num_5);
printf("2元:%d张\n", num_2);
printf("1元:%d张\n", num_1);
return 0;
}
阅读全文