//#include "stdio.h"
#include
int main(int argc, char* argv[])
{
int a=0,b=0,c=0,d=0,e=0;
printf("Enter a dollar amount:");
scanf("%d",&a);
if(a>=20)
{
b=int(a/20);
a=a-b*20;
}
if(a>=10&&a<20)
{
c=int(a/10);
a=a-c*10;
}
if(a>=5&&a<10)
{
d=int(a/5);
a=a-d*5;
}
if(a<5&&a>0)
{
e=a;
a=a-e;
}
printf("$20 bills:%d\n",b);
printf("$10 bills:%d\n",c);
printf("$5 bills:%d\n",d);
printf("$1 bills:%d\n",e);
return 0;
}
#include
void main()
{
int payment;
int S20,S10,S5,S1;
printf("Enter a dollar amount:");
scanf("%d",&payment);
fflush(stdin);
//payment=93;
S20=payment/20; //需要几个20$的大钞
S10=(payment%20)/10; //剩下的零头看需要几个10$的钞票
S5 =(payment%10)/5; //不足10$的零头需要几个5$的钞票
S1 =payment%5; //。。。只所以可以这样做是因为1,5,10,20恰好存在倍数的关系
printf("Payment %d need: $20x%d, $10x%d, $5x%d, $1x%d\n",payment,S20,S10,S5,S1);
}
#include "stdafx.h"
#include
int main(int argc, char* argv[])
{
int bill;
int par[4]={20,10,5,1};
int result[4];
printf("Enter a dollar amount:");
scanf("%d",&bill);
for(int i=0;i<4;i++)
{
result[i]=bill/par[i];
printf("printf("$%d bills:%d\n",par[i],result[i]);
bill%=par[i];
}
}
该程序适合现有人民币和美元。如果有一个国家的人民币包括20 15 10 5 几种面值,则程序失效。
另外,劝楼主养成编程的好习惯,尽量不要起并非显而易见的变量名。
#include
int main(void)
{
int amount;
printf("Enter a dollar amount: ");
scanf("%d", &amount);
printf("$20 bills: %d\n", amount / 20);
amount = amount % 20;
printf("$10 bills: %d\n", amount / 10);
amount = amount % 10;
printf("$5 bills: %d\n", amount / 5);
amount = amount % 5;
printf("$1 bills: %d\n", amount / 1);
}