#include<stdio.h>
#include<string.h>
struct books {
char name[31]; //30个字符串要31个以容纳'\0'
double price;
};
int main(void)
{
int n, i;
struct books book, min_book, max_book;
double min, max;
scanf("%d", &n);
for (i=0; i<n; i++) {
scanf("\n"); //必须读到 \n;
gets(book.name);
scanf("%lf", &book.price);
if (i==0) {
min_book = book;
max_book = book;
}
if (book.price < min_book.price) min_book = book;
if (book.price > max_book.price) max_book = book;
}
printf("%.2f, %s\n", max_book.price, max_book.name);
printf("%.2f, %s", min_book.price, min_book.name);
return 0;
}
习题9-4 查找书籍
最新推荐文章于 2021-08-08 22:31:33 发布