#include
#include
#include
#define N 10
typedef struct
{ char name[10];
double price;
struct { int year;int month;int day ;}date;
}STREC;
int fun(STREC a,double p)
{
int i,j=0;
double q;
for(i=0; i < N ; i++,a++)
{
q=a->price;
if(q>p)
{
*(a+j)=(a+i);
j++;
}
}
printf("价格在30元以上的商品数目共计:%d",j);
return j;
}
main()
{ STREC s;
s=(STREC *)malloc(10*sizeof(STREC));
int i,j;double p;
printf("\n请输入10种商品的数据包括品名、单价和出厂日期: ");
for(i=0; i < N; i++,s++)
{
scanf("%s %lf %d %d %d",s->name,&s->price,&s->date.year,&s->date.month,&s->date.day);
printf("%s %lf %d-%d-%d",s->name,s->price,s->date.year,s->date.month,s->date.day);
}
p=30.0;
j=fun(s,p);
printf("价格在30元以上的商品数目共计:%d",j);
for(i=0; i < j; i++)
{
printf("%s %lf %d-%d-%d",s->name,s->price,s->date.year,s->date.month,s->date.day);
}
printf("\n");
}
/
1.程序运行结果为:
请输入10种商品的数据包括品名、单价和出厂日期:
book 30.09 1930 9 30
fruit 99 2015 9 30
apples 9.9 2015 9 25
milk 56 2015 9 25
meat 19.8 2015 9 25
book 30.09 1930 9 30
fruit 99 2015 9 30
apples 9.9 2015 9 25
meat 19.8 2015 9 25
apples 9.9 2015 9 25
价格在30元以上的商品数目共计:0价格在30元以上的商品数目
共计:0====为何没有统计价格在30元以上的商品数目结果呢?
*/