浙大版《C语言程序设计(第3版)》题目集 习题9-4 查找书籍 (20分)

在这里插入图片描述

3
Programming in C
21.5
Programming in VB
18.5
Programming in Delphi
25.0
#include <stdio.h>
#include <string.h>
struct book
{
    double price;
    char name[31];
};
int main()
{
    int n, i, t1, t2;
    double max, min;
    struct book a[10];
    max = -1;
    min = 99999;
    t1 = t2 = 0;
    scanf("%d", &n);
    for (i = 0; i < n; i++)
    {
        scanf("\n");
        gets(a[i].name);
        scanf("%lf", &a[i].price);
        if (max < a[i].price)
        {
            max = a[i].price;
            t1 = i;
        }
        if (min > a[i].price)
        {
            min = a[i].price;
            t2 = i;
        }
    }
    printf("%.2lf, %s\n", a[t1].price, a[t1].name);
    printf("%.2lf, %s\n", a[t2].price, a[t2].name);
    return 0;
}
发布了252 篇原创文章 · 获赞 117 · 访问量 8545

猜你喜欢

转载自blog.csdn.net/qq_44458489/article/details/105321537