C++编程题:输入3个整型数,按由大到小的顺序输出显示!

2025-03-23 03:57:37
推荐回答(5个)
回答1:

使用冒泡排序既可以很容易的解决问题的呢,呵呵
源程序如下:
#include
#include
#define N 3
using namespace std;
int main()
{
int a,b,p[3],t;
cout<<"输入"< for(a=0;a cin>>p[a];
for(a=1;a for(b=0;b if(p[b] {
t=p[b];
p[b]=p[b+1];
p[b+1]=t;
}
cout<<"排序结果为:";
for(a=0;a cout< cout< return 0;
}

回答2:

#include
#include
#include

using namespace std;

int main()
{
cout<<"Plese input three int numbers:"< vector int_vec;
int n;
while(cin>>n)
{
int_vec.push_back(n);
}
sort(int_vec.begin(),int_vec.end());
vector::size_type i=0;
while(i!=int_vec.size())
{
cout< ++i;
}
cout< return 0;
}

调试过·可以得到正确结果。

回答3:

#include
using namespace std;
int main()
{
int a,b,c;
cin>>a>>b>>c;
if (a {
int temp=a;
a=b;
b=temp;
}
if (c>a)
{
cout< }
else if (c {
cout< }
else
{
cout< }

return 0;
}

回答4:

#include

int get_max(int a,int b,int c)
{
int max;
max=a;
if(b>a)
max=b;
if(c>max)
max=c;
return max;
}

int main()
{
int a,b,c;
int max;
printf("请输入三个整数\n");
scanf("%d%d%d",&a,&b,&c);
max=get_max(a,b,c);
printf("最大的数为%d\n",max);
return 0;
}

回答5:

#include
#include
#include
using
namespace
std;
int
main()
{
cout<<"Plese
input
three
int
numbers:"<vector
int_vec;
int
n;
while(cin>>n)
{
int_vec.push_back(n);
}
sort(int_vec.begin(),int_vec.end());
vector::size_type
i=0;
while(i!=int_vec.size())
{
cout<++i;
}
cout<return
0;
}
调试过·可以得到正确结果。