当前位置: 代码迷 >> C语言 >> 求高手指点~!感激不尽~!
  详细解决方案

求高手指点~!感激不尽~!

热度:174   发布时间:2007-03-29 10:41:21.0

#include<stdio.h>
int count=0, y=0;

int zhengshu(int a)
{
int k=0;

if(a>=100)
{k=a/100; y=a%100;count=count+k;}

else if(a<100 && a>=50)
{k=a/50; y=a%50;count=count+k;}

else if(a<50 && a>=20 )
{k=a/20;y=a%20;count=count+k;}

else if(a<20 && a>=10)
{k=a/10;y=a%10;count=count+k;}

else if(a<10 && a>=5)
{k=a/5;y=a%5;count=count+k;}

else if(a<5 && a>=2)
{k=a/2; y=a%2;count=count+k;}

else if(a<2)
{k=a; y=0; count=count+k;}

if(y>=1) zhengshu(y);

return count;


}

void main()
{
int num,tt;
puts("输入金额:");

scanf("%d",&num);
tt=zhengshu(num);


printf("最少需要%d张。\n",tt);

}


----------------解决方案--------------------------------------------------------
#include<stdio.h>
void main()
{
int s[7]={100,50,20,10,5,2,1} ,i=0,n,sum=0;
printf("input the num:\n");
scanf("%d",&n);
while(n)
{
sum+=n/s[i];
n%=s[i];
i++;
}
printf("%d",sum);
getch();
}
----------------解决方案--------------------------------------------------------
顺便把各种纸币数也输出


#include<stdio.h>
#include<conio.h>
void main()
{
int s[7]={100,50,20,10,5,2,1} ,i=0,n,sum=0;
printf("input the num:\n");
scanf("%d",&n);
while(n)
{
sum+=n/s[i];
if(n/s[i]!=0)
printf("%d张%d元\n",n/s[i],s[i]);
n%=s[i];

i++;
}
printf("共%d张\n",sum);
getch();
}
----------------解决方案--------------------------------------------------------
感谢各位高手的指教,哪个题我已经做出来了,也是用if做的,不过有点长了,最后哪位朋友用循环做的蛮短的方法也挺好的,再次谢谢各位高手。
----------------解决方案--------------------------------------------------------
  相关解决方案