当前位置:网站首页>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
边栏推荐
- Global and Chinese markets for laser assisted liposuction (LAL) devices 2022-2028: Research Report on technology, participants, trends, market size and share
- 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
- Summary of reasons for web side automation test failure
- 自动化的优点有哪些?
- Global and Chinese markets of hemoglobin analyzers in care points 2022-2028: Research Report on technology, participants, trends, market size and share
- 2022-2028 global industry research and trend analysis report on anterior segment and fundus OTC detectors
- SSM online examination system source code, database using mysql, online examination system, fully functional, randomly generated question bank, supporting a variety of question types, students, teache
- QTreeView+自定义Model实现示例
- Flutter 小技巧之 ListView 和 PageView 的各種花式嵌套
- At the age of 30, I changed to Hongmeng with a high salary because I did these three things
猜你喜欢
C语言指针经典面试题——第一弹
El Table Radio select and hide the select all box
MySQL develops small mall management system
2022-2028 global gasket plate heat exchanger industry research and trend analysis report
PHP book borrowing management system, with complete functions, supports user foreground management and background management, and supports the latest version of PHP 7 x. Database mysql
Hands on deep learning (34) -- sequence model
Hands on deep learning (40) -- short and long term memory network (LSTM)
C # use gdi+ to add text to the picture and make the text adaptive to the rectangular area
How to batch change file extensions in win10
2022-2028 global tensile strain sensor industry research and trend analysis report
随机推荐
Hands on deep learning (33) -- style transfer
2022-2028 global elastic strain sensor industry research and trend analysis report
2022-2028 global edible probiotic raw material industry research and trend analysis report
Global and Chinese markets of water heaters in Saudi Arabia 2022-2028: Research Report on technology, participants, trends, market size and share
Write a jison parser from scratch (4/10): detailed explanation of the syntax format of the jison parser generator
SQL replying to comments
Go context basic introduction
Sort out the power node, Mr. Wang he's SSM integration steps
百度研发三面惨遭滑铁卢:面试官一套组合拳让我当场懵逼
Golang Modules
Explanation of closures in golang
2022-2028 global small batch batch batch furnace industry research and trend analysis report
Global and Chinese market of air fryer 2022-2028: Research Report on technology, participants, trends, market size and share
Global and Chinese markets of thrombography hemostasis analyzer (TEG) 2022-2028: Research Report on technology, participants, trends, market size and share
Upgrading Xcode 12 caused Carthage to build cartfile containing only rxswift to fail
C语言指针面试题——第二弹
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
自动化的优点有哪些?
Summary of reasons for web side automation test failure
Hands on deep learning (45) -- bundle search