当前位置:网站首页>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
边栏推荐
- JDBC and MySQL database
- Logstack configuration details -- elasticstack (elk) work notes 020
- Global and Chinese trisodium bicarbonate operation mode and future development forecast report Ⓢ 2022 ~ 2027
- mmclassification 标注文件生成
- How can people not love the amazing design of XXL job
- 华为联机对战如何提升玩家匹配成功几率
- 2022-2028 global industry research and trend analysis report on anterior segment and fundus OTC detectors
- Golang Modules
- 2022-2028 global strain gauge pressure sensor industry research and trend analysis report
- Kubernetes CNI 插件之Fabric
猜你喜欢
2022-2028 global edible probiotic raw material industry research and trend analysis report
Function comparison between cs5261 and ag9310 demoboard test board | cost advantage of cs5261 replacing ange ag9310
2022-2028 research and trend analysis report on the global edible essence industry
2022-2028 global gasket plate heat exchanger industry research and trend analysis report
智慧路灯杆水库区安全监测应用
Normal vector point cloud rotation
JDBC and MySQL database
C language pointer classic interview question - the first bullet
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
How to batch change file extensions in win10
随机推荐
Hands on deep learning (38) -- realize RNN from scratch
`Example of mask ` tool use
Four common methods of copying object attributes (summarize the highest efficiency)
7-17 crawling worms (15 points)
Global and Chinese market of bipolar generators 2022-2028: Research Report on technology, participants, trends, market size and share
libmysqlclient. so. 20: cannot open shared object file: No such file or directory
AMLOGIC gsensor debugging
MySQL foundation 02 - installing MySQL in non docker version
Kotlin:集合使用
Baidu R & D suffered Waterloo on three sides: I was stunned by the interviewer's set of combination punches on the spot
Report on the development trend and prospect trend of high purity zinc antimonide market in the world and China Ⓕ 2022 ~ 2027
On Multus CNI
Function comparison between cs5261 and ag9310 demoboard test board | cost advantage of cs5261 replacing ange ag9310
How do microservices aggregate API documents? This wave of show~
Logstack configuration details -- elasticstack (elk) work notes 020
C语言指针经典面试题——第一弹
Regular expression (I)
Qtreeview+ custom model implementation example
[on February 11, 2022, the latest and most fully available script library collection of the whole network, a total of 23]
Hands on deep learning (44) -- seq2seq principle and Implementation