【程序填空题】查最贵的书和最便宜的书。【问题描述】编写程序,从键盘输入n(n<10)种书的名称和定价并存入结构体数组中,从中查找定价最高及最低的书名和定价,并输出。【输入形式】先输入书

【程序填空题】查最贵的书和最便宜的书。

【问题描述】

编写程序,从键盘输入n(n<10)种书的名称和定价并存入结构体数组中,从中查找定价最高及最低的书名和定价,并输出。

【输入形式】

先输入书总数n(整型,n<10),再依次输入每种书的名称(字符串)和定价。

【输出形式】

输出定价最高及最低的书名和定价。

【样例输入】(下画线部分表示输入)

Input n:3

Input the name,price of the 1 book:C 21.5

Input the name,price of the 2 book:VB 18.5

Input the name,price of the 3 book:Python 25.0

【样例输出】

The book with the max price:Python,25.0

The book with the min price:VB,18.5

【样例说明】

输出定价最高的书名和定价,再输出定价最低的书名和定价,格式为:

The book with the max price:%s,%.1f

The book with the min price:%s,%.1f

程序填空部分:

#include <stdio.h>

struct book {

    char name[20];

    float price;

}a[10];

int main()

{

    int i,n,max=0,min=0;

    printf("Input n:");

    scanf("%d",&n);

    for(i=0;i<n;i++)

    {

        printf("Input the name,price of the %d book:",    (1)    );

        scanf("%s%f",    (2)    ,&a[i].price);

    }

   for(i=1;i<n;i++)

  {

      if(a[i].price > a[max].price)

              (3)    ;

      if(a[i].price <     (4)    )

          min=i;

  }

  printf("The book with the max price:%s,%.1f\n",    (5)    ,a[max].price);

  printf("The book with the min price:%s,%.1f",a[min].name,a[min].price);

  return 0;

}

正确答案:

第一空: 

i+1

第二空: 

a[i].name

第三空: 

max=i

第四空: 

a[min].price

第五空: 

a[max].name

  • 2
    点赞
  • 16
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值