### Bubble Sort Random Array

Hi, I am new here and im looking for some help. I am trying to create an array with 800 element that are randomly arranged within the array. Once this is complete i want to use the bubble sort algorithm to organize the number in ascending order. I have the following code but it doesn't seem to work, Any help will be great help, Thanks

 ``123456789101112131415161718192021222324252627282930`` `````` #include #include #include #define BUBBLE 800 int main() { int array[BUBBLE]; int i, j; int temp = 0; srand(time(NULL)); for (i = 0; i < BUBBLE; i ++) { printf("%d \n", rand() % BUBBLE + 1); for (j = 0; j < BUBBLE; j++); { temp = array[j+1]; array[j+1] = array[j]; array[j] = temp; } } system("PAUSE"); return 0; }``````
 ``1234567891011121314151617181920212223242526272829303132333435363738394041424344454647`` ``````#include #include #include #define BUBBLE 800 int main() { int myArray[BUBBLE]; int i, j; int temp = 0; int num; srand(time(NULL)); //fill array for (i = 0; i < BUBBLE; i ++) { num = rand() % BUBBLE + 1; myArray[i] = num; } //sort array for(i = 0; i < BUBBLE; i++) { for (j = 0; j < BUBBLE-1; j++) { if (myArray[j] > myArray[j+1]) { temp = myArray[j]; myArray[j] = myArray[j+1]; myArray[j+1] = temp; } }/*End inner for loop*/ }/*End outer for loop*/ //print array for (i = 0; i < BUBBLE; i++) { printf("%d\n",myArray[i]); } system("PAUSE"); return 0; }/*End of main*/``````
Last edited on

thanks a million Yanson!
Topic archived. No new replies allowed.