fork download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #define MATRIX_ROWS 7
  4. #define MATRIX_COLS 7
  5. double **createMatrix(void)
  6. {
  7. double **rows = calloc(MATRIX_ROWS,sizeof(double*));
  8. for(register int x = 0;x<MATRIX_ROWS;x++)
  9. {
  10. rows[x] = calloc(MATRIX_COLS,sizeof(double));
  11. }
  12. return rows;
  13. }
  14. void populateMatrix(double **matrix)
  15. {
  16. for(register int x = 0;x<MATRIX_ROWS;x++)
  17. {
  18. for(register int y = 0;y<MATRIX_COLS;y++)
  19. {
  20. matrix[x][y] = (rand() % 10) + (double)(rand() % 10)/10;
  21. }
  22. }
  23. }
  24. void printMatrix(double **matrix)
  25. {
  26. puts("\t\tMatrix");
  27. for(register int x = 0;x<MATRIX_ROWS;x++)
  28. {
  29. printf("Row #%d: ",x+1);
  30. for(register int y = 0;y<MATRIX_COLS;y++)
  31. {
  32. printf("%.1f ",matrix[x][y]);
  33. }
  34. puts("");
  35. }
  36. }
  37. void getMin(double **matrix)
  38. {
  39. puts("\t\tFinding mins");
  40. double min;
  41. for(register int x = 0;x<MATRIX_ROWS;x++)
  42. {
  43. min = matrix[x][0];
  44. for(register int y = 0;y<MATRIX_COLS;y++)
  45. {
  46. if(matrix[x][y] < min)
  47. {
  48. min = matrix[x][y];
  49. }
  50. }
  51. printf("Row #%d, Min element: %.1f\n",x+1,min);
  52. puts("");
  53. }
  54. }
  55. int getNextMin(double **matrix)
  56. {
  57. puts("\t\tFinding next mins");
  58. return 0;
  59. }
  60.  
  61. int main(void)
  62. {
  63. double **matrix = createMatrix();
  64. populateMatrix(matrix);
  65. printMatrix(matrix);
  66. getMin(matrix);
  67. int minNextCount = getNextMin(matrix);
  68. //code here
  69. return 0;
  70. }
  71.  
Success #stdin #stdout 0s 2244KB
stdin
Standard input is empty
stdout
		Matrix
Row #1: 3.6 7.5 3.5 6.2 9.1 2.7 0.9 
Row #2: 3.6 0.6 2.6 1.8 7.9 2.0 2.3 
Row #3: 7.5 9.2 2.8 9.7 3.6 1.2 9.3 
Row #4: 1.9 4.7 8.4 5.0 3.6 1.0 6.3 
Row #5: 2.0 6.1 5.5 4.7 6.5 6.9 3.7 
Row #6: 4.5 2.5 4.7 4.4 3.0 7.8 6.8 
Row #7: 8.4 3.1 4.9 2.0 6.8 9.2 6.6 
		Finding mins
Row #1, Min element: 0.9

Row #2, Min element: 0.6

Row #3, Min element: 1.2

Row #4, Min element: 1.0

Row #5, Min element: 2.0

Row #6, Min element: 2.5

Row #7, Min element: 2.0

		Finding next mins