#include <stdio.h>
struct chanp
{
int chan_ID
char chan_Name[20]
float chan_Price
}
struct chanp chanp1[3] = {{1001,"Asdf",100.2},{1002,"Bsdf",123.3},{1003,"Cfd",3313.0}}
void main()
{
struct chanp* p
printf("Information: 产品编号 产品名称 产品价格\n")
for(p=chanp1p<chanp1+3p++)
{
printf("%d%10s%15.2f\n",p->chan_ID,p->chan_Name,p->chan_Price)
}
}
(2)
#include <stdio.h>瞎散
#include <string.h>
struct chanp
{
int chan_ID
char chan_Name[20]
float chan_Price
}
void main()
{
struct chanp chan1[3]
struct chanp* p
int id,findid
int n=0
char name[20]
float price
for(int i =0i<3i++)
{
printf("Input: 产品编号 产品名称 产品价格\n")scanf("%d%s%f",&id,name,&price)
chan1[i].chan_ID = id
strcpy(chan1[i].chan_Name,name)
chan1[i].chan_Price = price
}
printf("请输入ID:\n")
scanf("%d",&id)
for (p=chan1p<chan1+3p++)
{
if (id == p->chan_ID)
{
printf("该产品存在\n")
printf("Information: 产品编号 产品名称 产品价格\n")�n")
printf("%d%10s%15.2f\n",p->chan_ID,p->chan_Name,p->chan_Price)
n++
}
}
if (n == 0)
{
printf("该产品不存在\n")
}
}
(3)
#include <磨族氏stdio.h>
#include <stdlib.h>
#include <string.h>
struct chanp
{
int chan_ID
char chan_Name[20]
float chan_Price
}
void main()
{
struct chanp chan1[3]
struct chanp* p
int id,findid
char ch[10]
int n=0
char name[20]
float price
for(int i =0i<3i++)
{
printf("input: 产品编号 产品名称 产品价格�n")
scanf("%d%s%f",&id,name,&price)
chan1[i].chan_ID = id
strcpy(chan1[i].chan_Name,name)
chan1[i].chan_Price = price
}
printf("请输入查询产品的ID\n")
scanf("%d",&id)
for (p=chan1p<chan1+3p++)
{
if (id == p->chan_ID)
{
printf("产品存在。\n")
printf("需要修改产品信息请按Y或者y,否则请按任意键。\n")
scanf("%s",ch)
if (!strcmp(ch,"Y") || !strcmp(ch,"y"))
{
printf(" 请输入:产品名称 产品价格\n"穗灶)
scanf("%s%f",name,&price)
strcpy(p->chan_Name,name)
p->chan_Price = price
printf("Information: 产品编号 产品名称 产品价格\n")�n")
printf("%d%10s%15.2f\n",p->chan_ID,p->chan_Name,p->chan_Price)
}
n++
}
}
if (n == 0)
{
printf("该产品不存在。\n")
}
}
终于结束了
新鲜出炉,还有些BUG,缺和粗可以自行修改。
#include<stdio.h>
int main()
{
double rental//rental销售总额
double pri[5]={2.46,4.95,9.12,4.35,6.66}//pri[]零售价格
int i,num[5],count[5]//num[]名字棚链,sale[]销售数伏镇量
for (i=1i<6i++)
{
printf ("输入第%d种商品名字和销售量:\n",i)
scanf ("%d %d",&num[i],&count[i])//无法限制用户输入数据类型,可产生bug
printf ("商品名字:%d,价格:%f,销售量:%d\n",num[i],pri[i],count[i])//可注释
rental += pri[i]*count[i]//+=
}
printf ("销售总额是%f\n",rental)
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)