#include<stdio.h> struct book { char title[20]; double price; }; int main(void) { int i; struct book books[10],max,min; for (i = 0; i < 10; i++) { scanf("%s%lf", books[i].title, &books[i].price); } for (i = 0; i < 9; i++) { if (i == 0) max = books[i]; if (max.price < books[i].price) max = books[i]; if (i == 0) min = books[i]; if (min.price > books[i].price) min = books[i]; } printf("max——title:%s\tprice:%.2lf\n", max.title, max.price); printf("min——title:%s\tprice:%.2lf\n", min.title, min.price); return 0;
#include<stdio.h> #define NUMBER 10 struct book { char name[10]; float price; }; int main() { int i,maxl,minl; struct book test[NUMBER]; printf(“Input 10 book’s name and price\n”); for(i=0; i<NUMBER; i++) scanf(“%s%f”, test[i].name, &test[i].price); maxl=minl=0; for(i=1; i<NUMBER; i++) { if(test[maxl].price<test[i].price) maxl=i; if(test[minl] .price >test[i].price) minl=i; } printf(“Max Price: %f, %s\n”, test[maxl].price, test[maxl].name); printf(“Min Price: %f, %s\n”, test[minl].price, test[minl].name); return 0; }