当前位置:网站首页>Exercise 9-4 finding books (20 points)
Exercise 9-4 finding books (20 points)
2022-07-04 09:46:00 【skeet follower】
Given n The title and price of the book , This question requires the preparation of procedures , Find and output the name and price of the book with the highest and lowest price .
Input format :
Enter the first line to give a positive integer n(<10), Subsequently given n Information about this book . Each book gives its title in a line , That is, the length does not exceed 30 String , The next line gives a positive real price . The title guarantees that there is no book of the same price .
Output format :
In a row, press “ Price , Title ” The format output price is the highest and the lowest . Price retention 2 Decimal place .
sample input :
3
Programming in C
21.5
Programming in VB
18.5
Programming in Delphi
25.0
sample output :
25.00, Programming in Delphi
18.50, Programming in VB
The code is as follows :
#include <stdio.h>
struct books// Structure of definition book
{
char name[31];// Title
double price;// Price
};
int main()
{
int n,i,max=0,min=0;
double temp;
struct books a[10];
scanf("%d",&n);// The number of books
for(i=0;i<n;i++)
{
getchar();// absorption scanf Carriage return left by function
gets(a[i].name);//name
scanf("%lf",&a[i].price);//price
}
for(i=1;i<n;i++)// Find the most expensive one
{
if(a[i].price>a[max].price)
{
max=i;
}
}
for(i=1;i<n;i++)// Find the cheapest
{
if(a[i].price<a[min].price)
{
min=i;
}
}
printf("%.2lf, %s\n",a[max].price,a[max].name);
printf("%.2lf, %s",a[min].price,a[min].name);
return 0;
}
summary : This topic mainly pays attention to getchar() and gets() Usage of , Personally, I think this blog is excellent , Forget to have a look :getchar() and gets()_ Shao Guangming's blog -CSDN Blog _getchar and gets
边栏推荐
- Write a jison parser (7/10) from scratch: the iterative development process of the parser generator 'parser generator'
- 自动化的优点有哪些?
- 2022-2028 global industrial gasket plate heat exchanger industry research and trend analysis report
- Rules for using init in golang
- Hands on deep learning (38) -- realize RNN from scratch
- 2022-2028 global seeder industry research and trend analysis report
- 2022-2028 global edible probiotic raw material industry research and trend analysis report
- Kotlin 集合操作汇总
- Write a jison parser from scratch (2/10): learn the correct posture of the parser generator parser generator
- Lauchpad x | MODE
猜你喜欢
Baidu R & D suffered Waterloo on three sides: I was stunned by the interviewer's set of combination punches on the spot
H5 audio tag custom style modification and adding playback control events
PHP is used to add, modify and delete movie information, which is divided into foreground management and background management. Foreground users can browse information and post messages, and backgroun
2022-2028 global gasket metal plate heat exchanger industry research and trend analysis report
智慧路灯杆水库区安全监测应用
C # use gdi+ to add text with center rotation (arbitrary angle)
Web端自动化测试失败原因汇总
回复评论的sql
el-table单选并隐藏全选框
自动化的优点有哪些?
随机推荐
The child container margin top acts on the parent container
C语言指针面试题——第二弹
2022-2028 global intelligent interactive tablet industry research and trend analysis report
Hands on deep learning (46) -- attention mechanism
直方图均衡化
Hands on deep learning (45) -- bundle search
C # use gdi+ to add text to the picture and make the text adaptive to the rectangular area
Hands on deep learning (41) -- Deep recurrent neural network (deep RNN)
El Table Radio select and hide the select all box
Report on investment analysis and prospect trend prediction of China's MOCVD industry Ⓤ 2022 ~ 2028
Svg image quoted from CodeChina
Normal vector point cloud rotation
法向量点云旋转
品牌连锁店5G/4G无线组网方案
Hands on deep learning (36) -- language model and data set
Leetcode (Sword finger offer) - 35 Replication of complex linked list
Kubernetes CNI 插件之Fabric
Analysis report on the development status and investment planning of China's modular power supply industry Ⓠ 2022 ~ 2028
On Multus CNI
Write a jison parser from scratch (6/10): parse, not define syntax