10.28/例题2

#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;
}

posted @   fushuxuan1  阅读(5)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· 单线程的Redis速度为什么快?
· 展开说说关于C#中ORM框架的用法!
· Pantheons:用 TypeScript 打造主流大模型对话的一站式集成库
点击右上角即可分享
微信分享提示