n=5 786.98, 1038.76, 1503.72, 1234.98, 1653.33
用C语言实现 最好用数据结构的某些算法 谢谢高手
没有用数据结构,不过有几个函数比较重复,可能用数据结构能好些:
程序中输入的第一个数是待输入数据的个数,代码如下:
#include "stdio.h"
unsigned Yuan100;
int Yuan50=0,Yuan20=0,Yuan10=0,Yuan5=0,Yuan2=0,Yuan1=0;
int Jiao5=0,Jiao2=0,Jiao1=0;
int Fen5=0,Fen2=0,Fen1=0;
main()
{
int number,i;
float salary;
void CalMoney(float sal);
void shiyuan_turn(int x);
void yuan_gewei_turn(int x);
void jiao_turn(int x);
void fen_turn(int x);
printf("Input the number of works:\n");
scanf("%d",&number);
for(i=1;i<=number;i++)
{
printf("Input the %dth worker's salary(<32768):\n",i);
scanf("%f",&salary);
CalMoney(salary);
}
printf("Need 100yuan:%u\n",Yuan100);
printf("Need 50yuan:%d\t 20yuan:%d\t 10yuan:%d\n",Yuan50,Yuan20,Yuan10);
printf("Need 5yuan:%d\t 2yuan:%d\t 1yuan:%d\n",Yuan5,Yuan2,Yuan1);
printf("Need 5jiao:%d\t 2jiao:%d\t 1jiao:%d\n",Jiao5,Jiao2,Jiao1);
printf("Need 5fen:%d\t 2fen:%d\t 1fen:%d\n",Fen5,Fen2,Fen1);
}
void CalMoney(float sal)
{
long yuan,shiyuan;
int yuan_gewei,jiao,fen;
yuan=(int)sal;
shiyuan=(yuan%100)/10;
yuan_gewei=yuan%10;
jiao=(int)((sal-yuan)*10.0);
fen=(int)(sal*100.0)-yuan*100-jiao*10;
Yuan100+=yuan/100;
shiyuan_turn(shiyuan);
yuan_gewei_turn(yuan_gewei);
jiao_turn(jiao);
fen_turn(fen);
}
void shiyuan_turn(int x)
{
if(x<5)
;
else
{
Yuan50+=1;
x-=5;
}
switch(x)
{
case 0:break;
case 1:Yuan10+=1;break;
case 2:Yuan20+=1;break;
case 3:Yuan10+=1;Yuan20+=1;break;
case 4:Yuan20+=2;break;
default:break;
}
}
void yuan_gewei_turn(int x)
{
if(x<5)
;
else
{
Yuan5+=1;
x-=5;
}
switch(x)
{
case 0:break;
case 1:Yuan1+=1;break;
case 2:Yuan2+=1;break;
case 3:Yuan1+=1;Yuan2+=1;break;
case 4:Yuan2+=2;break;
default:break;
}
}
void jiao_turn(int x)
{
if(x<5)
;
else
{
Jiao5+=1;
x-=5;
}
switch(x)
{
case 0:break;
case 1:Jiao1+=1;break;
case 2:Jiao2+=1;break;
case 3:Jiao1+=1;Jiao2+=1;break;
case 4:Jiao2+=2;break;
default:break;
}
}
void fen_turn(int x)
{
if(x<5)
;
else
{
Fen5+=1;
x-=5;
}
switch(x)
{
case 0:break;
case 1:Fen1+=1;break;
case 2:Fen2+=1;break;
case 3:Fen1+=1;Fen2+=1;break;
case 4:Fen2+=2;break;
default:break;
}
}