Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <conio.h>
- int **allocateMatrix(int nRows, int nCols)
- {
- int **matrix = new int*[nRows];
- for (int i = 0; i < nRows; i++)
- matrix[i] = new int[nCols];
- return matrix;
- }
- void inputMatrix(int **matrix, int nRows, int nCols)
- {
- for (int i = 0; i < nRows; i++)
- for (int j = 0; j < nCols; j++)
- scanf("%d", &matrix[i][j]); // "%d", not "%d " !!!
- }
- void outputMatrix(int **matrix, int nRows, int nCols)
- {
- for (int i = 0; i < nRows; i++)
- {
- for (int j = 0; j < nCols; j++)
- printf("%d ", matrix[i][j]);
- printf("\n");
- }
- }
- void freeMatrix(int **matrix, int nRows)
- {
- for (int i = 0; i < nRows; i++)
- delete [] matrix[i];
- delete [] matrix;
- }
- void main()
- {
- int nRows = 0, nCols = 0;
- printf("Input number of rows and columns: ");
- scanf("%d%d", &nRows, &nCols);
- int **matrix = allocateMatrix(nRows, nCols);
- inputMatrix(matrix, nRows, nCols);
- printf("\n");
- outputMatrix(matrix, nRows, nCols);
- freeMatrix(matrix, nRows);
- getch();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement