From 13e216b5643e8b4fa5f9968b786ef6c1f8897b8f Mon Sep 17 00:00:00 2001 From: haoxuan Date: Fri, 13 Feb 2026 03:22:52 -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 输入五本书的价格,计算总价,找出最贵的书的价格,并把价格从低到高的顺序输出 。 --- 排序/162.cpp | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 排序/162.cpp diff --git a/排序/162.cpp b/排序/162.cpp new file mode 100644 index 0000000..fa3c796 --- /dev/null +++ b/排序/162.cpp @@ -0,0 +1,43 @@ +#include +#include +using namespace std; + +int main(){ + + //定义五本书的价格以及输入五本书的价格 + double a[5],sum,temp; + cout << "请输入五本书的价格:"<> a[i]; + sum += a[i]; + } + + //给这五个数排序我们用冒泡排序 + for(int i=0;i<5;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 << "书的价格从低到高依次是:"<