# Thread: Sorting an array of integers

1. ## Sorting an array of integers

hI, Does anyone know why this wont work, All im trying to do is simply sort an array of integers, its based on the bubblesort algorithm from the code snippets section of this site

Code:
```#include <windows.h>
#include <stdlib.h>
#include <stdio.h>

int A[11]= {12, 5, 7, 2, 56, 20, 43, 8, 31, 33, 14};
int x=0, y=0, n=11;

int main(void)
{
for(x; x<n; x++)
{
for(y; y<n-1; y++)
{
if(A[y]>A[y+1])
{
int temp = A[y+1];
A[y+1] = A[y];
A[y] = temp;
}
}

printf ("A[%d] = %d\n");
}

}```
but the output appears

Code:
```A[4007008] = 4008608
A[4007008] = 4008608
A[4007008] = 4008608
A[4007008] = 4008608
A[4007008] = 4008608
A[4007008] = 4008608
A[4007008] = 4008608
A[4007008] = 4008608
A[4007008] = 4008608
A[4007008] = 4008608
A[4007008] = 4008608```

2. Take a closer look at your use of printf(). Can you see what's missing?

3. Well it wouldn't hurt if you actually passed the variables to printf().
Code:
`printf ("A[%d] = %d\n", y, A[y]);`

4. Your output statement displays rubbish. and it should be in some kind of loop e.g
Code:
```    for ( x=0; x < n; ++x )
printf ("A[%d] = %d\n", x, A[x]);```
the y in this statement has no effect
Code:
`for(y; y<n-1; y++)`
make it
Code:
`for(y=0; y<n-1; y++)`
Same wit x in the outer loop. You could write it like this as well ( because x is initialized to 0 )
Code:
`for(; x<n; x++)`
Kurt

5. Excellent, works perfectly now i think, thanks for all the help