编写程序,从键盘输入 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
#include
struct mess
{
char name[100];
float price;
}mes[1024];
int main()
{
int i,n,x,y;
scanf("%d",&n);
float max=0,min=1024;
for(i=0;imes[i].price )
{
min=mes[i].price ;
y=i;
}
}
printf("highest price: %.1f, %s\n",mes[x].price ,mes[x].name );
printf("lowest price: %.1f, %s\n",mes[y].price ,mes[y].name );
}