I am new to programming in C, and have but one problem that I can't seem to figure out on my own.
I have created a 2-dimensional matrix and need to sort all 100 randomly generated numbers in the matrix using bubble sort. I also need to save the output for later use in my program. Has anybody got any idea?
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main() {
int i, j, matrix[10][10];
// Generate random numbers in a matrix
printf("Numbers generated:\n");
srand((int)time(NULL));
for(i=0; i<10; i++) {
for(j=0; j<9; j++) {
matrix[i][j] = (rand()%900) + 100;
printf("%d ", matrix[i][j]);
}
printf("\n");
}
// Sort matrix
for(i=0; i<10; i++) {
for(j=0; j<10; j++) {
// Sort algorithm goes here
}
}
// Present sorted matrix
printf("\nSorted matrix:\n");
for(i=0; i<10; i++) {
for(j=0; j<9; j++) {
printf("%d ", matrix[i][j]);
}
printf("\n");
}
return 0;
}
I would be most thankful for an answer!