C++程序题目,急!!!!

来源:百度知道 编辑:UC知道 时间:2024/06/03 18:42:47
输入三个数,求出三个数之中,,数值排在中间的数!
只需要显示出中间的数!

排序...

#include<iostream.h>
void main()
{
int a,b,c,temp;
cin>>a>>b>>c;
if(a>b)
{
temp=a;
a=b;
b=temp;
}
if(b>c)
{
temp=b;
b=c;
c=temp;
}
if(a>c)
{
temp=a;
a=c;
c=temp;
}
cout<<b<<endl;
}

#include<iostream.h>
void main()
{
int a,b,c,temp;
cin>>a>>b>>c;
cout<<(((a<b?b:a)<c)?(a<b?b:a):c)<<endl;
}

/*
如果是整数,下面的方法就比较简单。
三个数+起来,-掉最大和最小,剩下就是中间的
*/

#include <iostream>
#include <algorithm>

int main()
{
using namespace std;

int a,b,c;
cin>>a>>b>>c;
cout<<(a+b+c-max(a,max(b,c))-min(a,min(b,c)))<<endl;
return 0;
}