C language 12.0

If there are any biases, I still look at Haihan;
in the previous chapter, I talked about the offset problem, here is some explanation;
if it is a one-dimensional array; array[5]
contains 5 elements in this array; their The subscript is; 0,1,2,3,4;
the offset of array[5] is; 4 It
should be noted that the offset is the effective address;
in a two-dimensional array; array[2][3]; we It can be seen that he has 6 elements; the offset is; 5, the
popular understanding is; the distance between the element and the first element; the
three-dimensional array array[i][j][n]: array[a][k][ m] The
offset is a j n+k*n=m;
OK, don’t talk nonsense,
let’s get to the main topic; today, I will talk about the array sorting algorithm; the
selection method sorting;

int main()
{
int i,j;
int array[10];
int ipos,itemp;// define array, variable;
for(i=0;i<10;i++)
{
printf("array[i]=" ,i);
scanf("%d",&array[i]);//First input operation;
}
for(i=0;i<9;i++)//Specific operation;
{
ipos=i;
itemp =array[i];//First assign value, define the first number, the smallest;
for(j=i+1;j<10;j++)// Compare the following, compare the first number with the last nine numbers ;
{
If(array[j]<itemp)
{
itemp=array[j];
ipos=j;
}
} // Find the smallest number in a loop;
array[ipos]=array[i];//Exchange , Exchange the lowest number obtained above
array[i]=itemp;
}
for(i=0;i<10;i++)
{
printf("%d\t",i);
if(i== 4)// Judgment, switch line;
printf("\n");
}
return 0;
}
This can be ranked;

Guess you like

Origin blog.51cto.com/15098536/2627760