C++ 排序算法给出错误的结果 #包括 #包括 使用名称空间std; int main() { int a,b,c[5],d; coutc[a]; } 对于内环中的(a=0;a

C++ 排序算法给出错误的结果 #包括 #包括 使用名称空间std; int main() { int a,b,c[5],d; coutc[a]; } 对于内环中的(a=0;a,c++,sorting,bubble-sort,C++,Sorting,Bubble Sort,而言,它应该是a+1而不是+a对于(a=0;a对于(a=0;ano,no no@Marounnaroun很抱歉,如果这是一个坏习惯,那么这是我最后一次。你能不能不使用std::sort?@Ralara:标题的原始格式确实表明这是一项分配为练习的任务。如果你提供一份案头检查的成绩单,那会很有帮助,这样我们就可以帮助你找出你的程序的确切位置am的行为与您期望的不同。是的,这就是我的意思,但我不知道第二个循环是导致输出的循环,非常感谢@quetzalcatla #include<iostream

而言,它应该是
a+1
而不是
+a
对于(a=0;a
对于(a=0;ano,no no@Marounnaroun很抱歉,如果这是一个坏习惯,那么这是我最后一次。你能不能不使用std::sort?@Ralara:标题的原始格式确实表明这是一项分配为练习的任务。如果你提供一份案头检查的成绩单,那会很有帮助,这样我们就可以帮助你找出你的程序的确切位置am的行为与您期望的不同。是的,这就是我的意思,但我不知道第二个循环是导致输出的循环,非常感谢@quetzalcatla
#include<iostream>
#include<conio.h>

using namespace std;

int main()
{
    int a, b, c[5], d;

    cout << "enter any five number\n";
    for(a=0; a<5; a++)
    {
        cin>>c[a];
    }
    for(a=0; a<5; a++)
    {
        for(b=++a; b<5; b++)
        {
            if(c[b] < c[a])
            {
                d = c[b];
                c[b] = c[a];
                c[a] = d;
            }
        }       
    }

    cout << "\nhere is the entered numbers in order\n"; 
    for(a=0; a<5; a++)
    {
        cout << c[a];
        cout << endl;
    }
    getch();
    return 3;
}
   for(a=0; a<5; a++)
    {
        for(b=++a; b<5; b++)
        {
            if(c[b] < c[a])
            {
                d = c[b];
                c[b] = c[a];
                c[a] = d;
            }
        }       
    }
for(a=0; a<4; a++)
{
    for(b=a+1; b<5; b++)
    {
        if(c[b] < c[a])
        {
            d = c[b];
            c[b] = c[a];
            c[a] = d;
        }
    }       
}
for(a=0; a<5-1; a++){
  for(b=0; b<5-a-1; b++){
    if(c[b] < c[a]){
      d = c[b];
      c[b] = c[a];
      c[a] = d;
    }
  }
}