当前位置:网站首页>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.0sample output :
25.00, Programming in Delphi
18.50, Programming in VBThe 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
边栏推荐
- 2022-2028 global visual quality analyzer industry research and trend analysis report
- el-table单选并隐藏全选框
- 2022-2028 global intelligent interactive tablet industry research and trend analysis report
- Write a jison parser from scratch (3/10): a good beginning is half the success -- "politics" (Aristotle)
- Regular expression (I)
- Normal vector point cloud rotation
- Global and Chinese markets for laser assisted liposuction (LAL) devices 2022-2028: Research Report on technology, participants, trends, market size and share
- 2022-2028 global seeder industry research and trend analysis report
- About the for range traversal operation in channel in golang
- Solution to null JSON after serialization in golang
猜你喜欢

2022-2028 global tensile strain sensor industry research and trend analysis report

Svg image quoted from CodeChina

Hands on deep learning (43) -- machine translation and its data construction

Hands on deep learning (40) -- short and long term memory network (LSTM)

Hands on deep learning (41) -- Deep recurrent neural network (deep RNN)

Machine learning -- neural network (IV): BP neural network

Hands on deep learning (45) -- bundle search

2022-2028 global gasket plate heat exchanger industry research and trend analysis report

2022-2028 global gasket metal plate heat exchanger industry research and trend analysis report

回复评论的sql
随机推荐
Go context basic introduction
Hands on deep learning (46) -- attention mechanism
Global and Chinese PCB function test scale analysis and development prospect planning report Ⓑ 2022 ~ 2027
Write a jison parser from scratch (2/10): learn the correct posture of the parser generator parser generator
Write a mobile date selector component by yourself
libmysqlclient. so. 20: cannot open shared object file: No such file or directory
C # use gdi+ to add text to the picture and make the text adaptive to the rectangular area
How does idea withdraw code from remote push
165 webmaster online toolbox website source code / hare online tool system v2.2.7 Chinese version
Ultimate bug finding method - two points
JDBC and MySQL database
Global and Chinese market of planar waveguide optical splitter 2022-2028: Research Report on technology, participants, trends, market size and share
2022-2028 global edible probiotic raw material industry research and trend analysis report
2022-2028 global strain gauge pressure sensor industry research and trend analysis report
Development trend and market demand analysis report of high purity tin chloride in the world and China Ⓔ 2022 ~ 2027
MySQL transaction mvcc principle
Summary of the most comprehensive CTF web question ideas (updating)
Explanation of closures in golang
Implementing expired localstorage cache with lazy deletion and scheduled deletion
Lauchpad X | 模式