编写程序,从键盘输入 n (n<10)本书的名称和定价并存入结构数组中,查找并输出其中定价最高和最低的书的名称和定价。
输出格式语句:
printf("highest price: %.1f, %s\n", );
printf("lowest price: %.1f, %s\n",);
输入输出示例:括号内为说明,无需输入输出
输入样例:
3 (n=3)
Programming in C
21.5
Programming in VB
18.5
Programming in Delphi
25
输入样例:
highest price: 25.0, Programming in Delphi
lowest price: 18.5, Programming in VB
#include<stdio.h>
struct book{
float price;
char title[80];
};
int main()
{
struct book a[10];
int i,n,max=0,min=0;
scanf("%d",&n);
for(i=0;i<n;i++)
{
getchar();
gets(a[i].title);
scanf("%f",&a[i].price);
if(a[i].price>a[max].price)
max=i;
if(a[i].price<a[min].price)
min=i;
}
printf("highest price: %.1f, %s\n",a[max].price,a[max].title);
printf("lowest price: %.1f, %s\n",a[min].price,a[min].title);
}