chaxunzhidingjiage.h

来自「C语言写的商品信息管理系统 学习数据结构」· C头文件 代码 · 共 42 行

H
42
字号
///////////////任意指定对商品进行价格排序        11
void chaxunzhidingjiage(struct shangpin shangp[],int count)
{
    struct shangpin sp[MAXLENTH];
    struct shangpin sptemb;
    int total=-1;
    int i=0,j=0;
    int low,high;
   	printf("\n\t\t 请输入最底价格:");
   	scanf("%d",&low);
   	printf("\n\t\t 请输入最高价格:");
   	scanf("%d",&high);
    for(i=0;i<count;i++)
	{
		if(shangp[i].price>low && shangp[i].price<high)
		{
            total=total+1;
            sp[total]=shangp[i];;
	   	}
	}
     for(i=0;i<total;i++)
     {
         for(j=total;j>i;j--)
            if(sp[j-1].price>sp[j].price)
            {
                sptemb=sp[j];
                sp[j]=sp[j-1];
                sp[j-1]=sptemb;
            }
     }
     for(i=0;i<=total;i++)
     {
         printf("\n\t\t _________________________________"); 
         printf("\n\t\t 商品编号:%d",sp[i].id); 
         printf("\n\t\t 商品名称:%s",sp[i].spname); 
         printf("\n\t\t 商品价格:%.2f",sp[i].price); 
         printf("\n\t\t 商品库存:%d",sp[i].kucun); 
     }
     printf("\n\t\t 查询完成,按任意键继续其他操作...."); 
	 getchar();getchar();
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?