#include
#define LEN 8
typedef struct{
int par;
int num;
}CENT;
int Calc(CENT cents[],int val);
int Show(CENT cents[],char *names[]);
int main()
{
char *names[LEN]={"£2","£1","50p","20p","10p","5p","2p","1p"};
int value,total;
CENT cents[LEN]={{200},{100},{50},{20},{10},{5},{2},{1}};
while(1)
{
printf("Input value:");
scanf(" %d",&value);
if(value <= 0)
break;
total = Calc(cents,value);
printf("%3d cents:",total);
Show(cents,names);
}
return 0;
}
int Calc(CENT cents[],int val)
{
int i;
int total;
if(!cents || val <= 0)
return 0;
for(i=0;i
cents[i].num = 0;
}
for(i=0,total=0;i
while(val >= cents[i].par)
{
++cents[i].num;
++total;
val -=cents[i].par;
}
}
return total;
}
int Show(CENT cents[],char *names[])
{
int i;
if(!cents || !names)
return 0;
for(i=0;i
if(cents[i].num)
printf("%2d x %s ",cents[i].num,names[i]);
}
puts("");
return 1;
}