MT1112 中庸之道
请编写一个简单程序,输入3个整数,比较他们的大小,输出中间的那个数
格式
输入格式:
输入整型,空格分隔
输出格式:输出整型
样例 1
输入:1 5 3
输出:3
比较:
#include<bits/stdc++.h>
using namespace std;
int main()
{
int a,b,c;
cin>>a>>b>>c;
if(a>b)
{
if(b>c)
cout<<b;
else
{
if(a>c)
cout<<c;
else
cout<<a;
}
}
else
{
if(a>c)
cout<<a;
else
{
if(b>c)
cout<<c;
else
cout<<b;
}
}
return 0;
}
sort函数:
#include<bits/stdc++.h>
using namespace std;
int main()
{
int a[3];
for(int i=0;i<3;i++)
cin>>a[i];
sort(a,a+3);
cout<<a[1];
return 0;
}