There is 2D array with pointers from user, filled with random numbers, program count sum of every row. I need to sort array by sum of every row and print it. For example if we have array:1 2 2 (sum=5)2 9 9 (sum=20)2 1 6 (sum=9) output should be:1 2 2 (sum=5)2 1 6 (sum=9)2 9 9 (sum=20). Thanks for help.
int main () {
int i, j, row, column, **array,sum;
time_t seconds;
time (&seconds);
srand ((unsigned int)seconds );
printf ("Write number of rows:");
scanf ("%d", &row);
printf ("Write number of columns:");
scanf ("%d", &column);
array=(int**) malloc (row * sizeof(int *));
if (array!=NULL){
for (i=0; i<row;i++)
array[i]= (int*) malloc (column *sizeof(int));
}
for (i=0; i<row;i++)
for (j=0; j<column;j++)
array[i][j]=(rand()%100);
for (i=0; i<row;i++){
for (j=0; j<column;j++)
printf("%d ",array[i][j] );
printf ("\n");
}
for(i=0;i<row;i++){ //find sum of each row
sum=0;
for(j=0;j<column;j++){
sum=sum+array[i][j];
}
printf("%d \n",sum);
}
return 0;
}