栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > C/C++/C#

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

C/C++/C# 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

【程序填空题】查最贵的书和最便宜的书。【问题描述】编写程序,从键盘输入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

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

    {

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

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

    }

   for(i=1;i

  {

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

              (3)    ;

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

          min=i;

  }

  printf("The book with the max price:%s,%.1fn",    (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

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/714490.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号