I compiled the following C++ program for array sorting on my PC using dev C++ 6.30 with TDM-GCC 9.2.0 compiler. I get the following (undesirable) output:
2 4 5 9 23 69
Now, by using an online compiler of programizer, I get the following (desired/expected) output:
2 4 5 9 23 88
This is the code:
#include <iostream>
using namespace std;
int main()
{
int i, cnt, x;
//int Arr[6];
int Arr[6] = {2, 9, 23, 88, 5, 4, };
for (cnt = 1; cnt < 6; cnt++)
{
for(i=0; i<6; i++)
{
if ( Arr[i] > Arr[i+1])
{
x = Arr[i];
Arr[i] = Arr[i+1];
Arr[i+1] = x;
}
}
}
// Printing the sorted array
for (int j=0; j<6; j++)
cout << Arr[j] << "\t";
}