7-12 查找书籍 (20分)

#includestruct book{
    char name[35];
        double price;}b[15];int main(){
    int n,i,j;    
    scanf("%d",&n);
    for(i=0;i<n;i++)
       {
               getchar();
               gets(b[i].name);
		scanf("%lf",&b[i].price);}
	 double max,min;    
	 max=min=b[0].price;    
	 int k=0,m=0;    
	 for(i=0;i<n;i++){        
	 if(b[i].price>max){            
	 max=b[i].price;            
	 k=i;        
	 }        
	 if(b[i].price<min){            
	 min=b[i].price;            
	 m=i;        
	 }    
	 }    
	 printf("%.2lf, %s\n",b[k].price,b[k].name);   
	 printf("%.2lf, %s\n",b[m].price,b[m].name); 
return 0;}

你可能感兴趣的:(C语言复习)