全部版块 我的主页
论坛 站务区 十一区 新手入门区
531 2
2020-02-03
struct book{
        char ch[3];
        int price;
};
void find(struct book book[],int i,struct book* min,struct book* max){
        struct book* book2;
        min=book;
        max=book;
        book2=book;
        int k;
        for(k=0;k<i;k++,book2++){
                if((book2->price)>=(max->price)){
                        *max=*book2;
                }
                if((book2->price)<=(min->price)){
                        *min=*book2;
                }
        }
}
int main(void){
        struct book b[3],*max,*min;
        int i;
        for(i=0;i<3;i++){
                printf("请输入书名:\n");
                scanf("%s",&b[i].ch);
                printf("请输入价格:\n");
                scanf("%d",&b[i].price);
        }
        max=b;//为什么一定要赋值?
        min=b;//为什么一定要赋值?
        find(b,3,min,max);
        printf("min is %s,price is %d",min->ch,min->price);
        printf("max is %s,price is %d",max->ch,max->price);
        return 0;
}

二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

全部回复
2020-2-4 12:03:58
请大家帮忙找一下程序中的问题,为什么得不出想要的输出?是哪里存在问题呢?
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2020-2-4 12:04:26
请大家帮忙找一下程序中的问题,为什么得不出想要的输出?是哪里存在问题呢?
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

栏目导航
热门文章
推荐文章

说点什么

分享

扫码加好友,拉您进群
各岗位、行业、专业交流群