C++ 根据我的建议,解决未修正序列(4,3,2,1,5)并将其更改为修正序列
我试图解决这个问题,并建议我做升序排列,从小数字升序到高数字,以获得正确的序列 所以我用C++编写了这个代码:-< /p>C++ 根据我的建议,解决未修正序列(4,3,2,1,5)并将其更改为修正序列,c++,arrays,sorting,sequence,C++,Arrays,Sorting,Sequence,我试图解决这个问题,并建议我做升序排列,从小数字升序到高数字,以获得正确的序列 所以我用C++编写了这个代码:-< /p> include<iostream.h> int main() { int ar[5] = {4,3,2,1,5}; int d; for (int i=0; i<=4; i++) cout<<ar[i]<<" "; cout<<endl;
include<iostream.h>
int main()
{
int ar[5] = {4,3,2,1,5};
int d;
for (int i=0; i<=4; i++)
cout<<ar[i]<<" ";
cout<<endl;
for (int x=0; x<=4; x++)
{
for(int y=x+1; y<=4; y++)
if(ar[x] > ar[y])
{
d=ar[x];
ar[x]=ar[y];
ar[y]=d;
for ( d=0; d<=4; d++)
{
cout<<ar[d]<<" ";
}
return 0;
}
}
}
这是我第一次和cplus在一起
那么,我的条件有什么问题
关于算法是正确的。你把牙套弄得有点乱
#include <iostream>
using std::cout;
using std::cin;
using std::endl;
int main()
{
int ar[5] = {4,3,2,1,5};
int d;
for (int i=0; i<=4; i++)
cout<<ar[i]<<" ";
cout<<endl;
for (int x=0; x<=4; x++)
{
for(int y=x+1; y<=4; y++)
if(ar[x] > ar[y])
{
d=ar[x];
ar[x]=ar[y];
ar[y]=d;
}
}
for ( d=0; d<=4; d++)
{
cout<<ar[d]<<" ";
}
return 0;
}
#包括
使用std::cout;
使用std::cin;
使用std::endl;
int main()
{
int-ar[5]={4,3,2,1,5};
int d;
对于(int i=0;i
#include <iostream>
using std::cout;
using std::cin;
using std::endl;
int main()
{
int ar[5] = {4,3,2,1,5};
int d;
for (int i=0; i<=4; i++)
cout<<ar[i]<<" ";
cout<<endl;
for (int x=0; x<=4; x++)
{
for(int y=x+1; y<=4; y++)
if(ar[x] > ar[y])
{
d=ar[x];
ar[x]=ar[y];
ar[y]=d;
}
}
for ( d=0; d<=4; d++)
{
cout<<ar[d]<<" ";
}
return 0;
}