当前位置:网站首页>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 from scratch (3/10): a good beginning is half the success -- "politics" (Aristotle)
- Flutter 小技巧之 ListView 和 PageView 的各種花式嵌套
- PHP student achievement management system, the database uses mysql, including source code and database SQL files, with the login management function of students and teachers
- What are the advantages of automation?
- Analysis report on the production and marketing demand and investment forecast of tellurium dioxide in the world and China Ⓣ 2022 ~ 2027
- 智能网关助力提高工业数据采集和利用
- 法向量点云旋转
- Hands on deep learning (45) -- bundle search
- PHP personal album management system source code, realizes album classification and album grouping, as well as album image management. The database adopts Mysql to realize the login and registration f
- Global and Chinese market of bipolar generators 2022-2028: Research Report on technology, participants, trends, market size and share
猜你喜欢
Hands on deep learning (33) -- style transfer
2022-2028 global special starch industry research and trend analysis report
Hands on deep learning (44) -- seq2seq principle and Implementation
Matlab tips (25) competitive neural network and SOM neural network
2022-2028 global small batch batch batch furnace industry research and trend analysis report
2022-2028 global industry research and trend analysis report on anterior segment and fundus OTC detectors
Ultimate bug finding method - two points
Nuxt reports an error: render function or template not defined in component: anonymous
Daughter love in lunch box
Mmclassification annotation file generation
随机推荐
Upgrading Xcode 12 caused Carthage to build cartfile containing only rxswift to fail
Report on the development trend and prospect trend of high purity zinc antimonide market in the world and China Ⓕ 2022 ~ 2027
Modules golang
Launpad | 基礎知識
自动化的优点有哪些?
2022-2028 global industry research and trend analysis report on anterior segment and fundus OTC detectors
C语言指针经典面试题——第一弹
How does idea withdraw code from remote push
Daughter love in lunch box
Analysis report on the development status and investment planning of China's modular power supply industry Ⓠ 2022 ~ 2028
QTreeView+自定义Model实现示例
Golang 类型比较
About the for range traversal operation in channel in golang
Global and Chinese market of bipolar generators 2022-2028: Research Report on technology, participants, trends, market size and share
直方图均衡化
Investment analysis and future production and marketing demand forecast report of China's paper industry Ⓥ 2022 ~ 2028
Trees and graphs (traversal)
C language pointer classic interview question - the first bullet
C # use smtpclient The sendasync method fails to send mail, and always returns canceled
品牌连锁店5G/4G无线组网方案