Home > Back-end >  Small white about the simplest sort, C has been wrong, please take a look at what the problem is.
Small white about the simplest sort, C has been wrong, please take a look at what the problem is.

Time:03-30

Write a small program, randomly generated array within 100-100, and since the childhood to the array of sorting, but program run down has been the first number is the biggest, starting from the second number is right, is this why?
The code is as follows:

# include "stdafx. H"
# include "iostream"
# include "time. H"
# include "cstdlib
"
Const int num=100;
using namespace std;

A void show_ar (int *);

Int main ()
{
Int ar (num);
Srand (time (0));
for (int i=0; i Ar [I]=rand () % 100;
Show_ar (ar);
//rearrangement arrary.
cout <"After rearrangement: \ n";
for (int i=0; i {
Int temp=ar [I];
int index=0;
For (int j=I + 1; j {
If (temp & gt;=ar [j])
{
Temp=ar [j];
The index=j;
}
}
Ar=ar [index] [I];
Ar [I]=temp;
}
Show_ar (ar);


return 0;
}

A void show_ar (int *)
{
for (int i=0; i {
If (a [I] <10)
cout <"";
cout If ((I + 1) % 10==0)
cout }
}
The results are as follows:

  • Related