From 21a6a16219ce92fcb837b05413ed23ed75eeb80a Mon Sep 17 00:00:00 2001 From: haoxuan Date: Fri, 13 Feb 2026 05:26:53 -0500 Subject: [PATCH] =?UTF-8?q?=E4=B8=8A=E4=BC=A0=E6=96=87=E4=BB=B6=E8=87=B3?= =?UTF-8?q?=E3=80=8C=E6=8E=92=E5=BA=8F=E3=80=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 买五本书,总价,最高价,排序输出 --- 排序/书的价格.cpp | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 排序/书的价格.cpp diff --git a/排序/书的价格.cpp b/排序/书的价格.cpp new file mode 100644 index 0000000..30c54ad --- /dev/null +++ b/排序/书的价格.cpp @@ -0,0 +1,36 @@ +#include +using namespace std; +int main(){ + double a[5]; + double sum=0,temp=0; + cout<<"请输入五本书的价格:"; + // 输入五本书的价格 + for (int i=0;i<5;i++) + { + cin>>a[i]; + sum += a[i]; + } + + // 排序 + for(int i=0;i<4;i++){ + for(int j=0;j<5-i-1;j++){ + if(a[j]>a[j+1]){ + temp=a[j]; + a[j]=a[j+1]; + a[j+1]=temp; + } + } + } + + cout<<"五本书的价格按从低到高的顺序排是:"; + for(int i=0;i<5;i++){ + cout<