10.28/例题2

发布时间 2023-10-28 09:41:17作者: fushuxuan1

#include <bits/stdc++.h>
using namespace std;
int a[6],n,sum=0,p,t;
void one(){
for(int i=0;i<5;i++){
for(int j=0;j<5-i;j++){
if(a[j]<a[j+1]){
t=a[j];
a[j]=a[j+1];
a[j+1]=t;
}
}
}
for(int x=0;x<5;x++){
cout<<a[x]<<" ";
}
}
void two(){
for(int i=0;i<5;i++){
for(int j=0;j<5-i;j++){
if(a[j]>a[j+1]){
t=a[j];
a[j]=a[j+1];
a[j+1]=t;
}
}
}
for(int x=1;x<=5;x++){
cout<<a[x]<<" ";
}
}
void three(){
for(int k=0;k<5;k++){
sum+=a[k];
}
p=sum/5;
cout<<p;
}
void four(){
for(int q=0;q<5;q++){
sum+=a[q];
}
cout<<sum;
}
int main(){
for(int i=0;i<5;i++){
cin>>a[i];
}
cin>>n;
switch(n){
case 1:
one();
break;
case 2:
two();
break;
case 3:
three();
break;
case 4:
four();
break;
default:cout<<"你输入错误了";
}
return 0;
}