include
using namespace std;
int main(){
int a[101],max=0,n=0,b;
for(int i=0;i<=4;i++){
cin>>a[i];
}
cin>>n;
switch(n){
case 1:
for(int i=0;i<5;i++){
for(int j=i;j<5;j++){
if(a[j]>a[i])swap(a[i],a[j]);
}
cout<<a[i]<<" ";
}
break;
case 2:
for(int i=0;i<5;i++){
for(int j=i;j<5;j++){
if(a[i]>a[j])swap(a[i],a[j]);
}
cout<<a[i]<<" ";
}
break;
case 3:
b=a[0]+a[1]+a[2]+a[3]+a[4];
cout<<b/5;
break;
default:
cout<<"“你输入错误了!!!”";
break;
}
return 0;
}
include
using namespace std;
void b(){
int a[101],max;
}
int main(){
int a[101],max=0,n=0,b;
for(int i=0;i<=4;i++){
cin>>a[i];
}
cin>>n;
switch(n){
case 1:
for(int i=0;i<5;i++){
for(int j=0;j<5-i;j++){
if(a[j]<a[i+1]){
max=a[j];
a[j]=a[j+1];
a[j+1]=max;
}
}
}
for(int i=0;i<5;i++){
cout<<a[i]<<" ";
}
break;
case 2:
for(int i=0;i<5;i++){
for(int j=i;j<5;j++){
if(a[i]>a[j])swap(a[i],a[j]);
}
cout<<a[i]<<" ";
}
break;
case 3:
b=a[0]+a[1]+a[2]+a[3]+a[4];
cout<<b/5;
break;
default:
cout<<"“你输入错误了!!!”";
break;
}
return 0;
}
标签:case,cout,int,max,cin,Switch,swap,例题 From: https://www.cnblogs.com/boyeyuan/p/17793679.html