44 lines
760 B
C++
44 lines
760 B
C++
#include<iostream>
|
|
#include<iomanip>
|
|
using namespace std;
|
|
|
|
int main(){
|
|
|
|
//定义五本书的价格以及输入五本书的价格
|
|
double a[5],sum,temp;
|
|
cout << "请输入五本书的价格:"<<endl;
|
|
for (int i=0 ;i<5;i++){
|
|
cin >> 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 << "书的价格从低到高依次是:"<<endl;
|
|
for (int i=0;i<5;i++){
|
|
cout << a[i]<<" ";
|
|
}
|
|
|
|
cout << endl <<"最贵的书的价格是:"<<a[4]<<endl;
|
|
cout << "书的总价格是:"<<sum<<endl;
|
|
|
|
return 0;
|
|
}
|
|
|
|
|
|
|
|
|