fork download
  1. #include <iostream>
  2. #include <ctime>
  3.  
  4. template <int ROWS, int COLUMNS>
  5. struct Matrix
  6. {
  7. int rows = ROWS;
  8. int columns = COLUMNS;
  9. int matrix[ROWS][COLUMNS] = {};
  10.  
  11. void produceMatrix()
  12. {
  13. for (int i = 0; i < rows; i++)
  14. {
  15. for (int j = 0; j < columns; j++)
  16. {
  17. matrix[i][j] = rand() % 10 + 1;
  18. }
  19. }
  20. }
  21.  
  22. void showMatrix()
  23. {
  24. for (int i = 0; i < rows; i++)
  25. {
  26. for (int j = 0; j < columns; j++)
  27. {
  28. std::cout << matrix[i][j] << "\t";
  29. }
  30. std::cout << std::endl;
  31. }
  32. }
  33. };
  34.  
  35.  
  36. int main()
  37. {
  38. srand(time(0));
  39. Matrix<3,4> a;
  40. a.produceMatrix();
  41. a.showMatrix();
  42. }
Success #stdin #stdout 0s 4176KB
stdin
Standard input is empty
stdout
1	5	5	8	
4	6	4	9	
3	5	1	2