Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Dichiarazione Librerie */
- #include <stdio.h>
- #include <stdlib.h>
- /* Dichiarazione Prototipi di funzione */
- /* Dichiarazione Funzioni*/
- int main ()
- {
- int i, // var
- j, // var
- lines, // var
- columns, // var
- **intMatrix; // pointer
- printf("Type the matrix lines> ");
- scanf("%d", &lines); /* add a validation */
- printf("Type the matrix columns> ");
- scanf("%d", &columns); /* add validation */
- intMatrix = (int **)malloc(lines * sizeof(int *));
- //pointer to an array of [lines] pointers
- for (i = 0; i < lines; ++i)
- intMatrix[i] = (int *)malloc(columns * sizeof(int));
- //pointer to a single array with [columns] integers
- /* Adding var to matrix */
- for (i = 0; i < lines; ++i)
- for (j = 0; j < columns; ++j)
- {
- printf("Type a number for <line: %d, column: %d>", i+1, j+1);
- scanf("%d", &intMatrix[i][j]); // add validation
- }
- /* Print at video of matrix maded */
- for (i = 0; i < lines; ++i)
- {
- for (j = 0; j < columns; ++j)
- {
- printf("Number: %d, < line: %d column: %d >\n", intMatrix[i][j], i+1, j+1);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement