Advertisement
Guest User

Untitled

a guest
Dec 11th, 2019
175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.10 KB | None | 0 0
  1. /* Dichiarazione Librerie */
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4.  
  5. /* Dichiarazione Prototipi di funzione */
  6.  
  7.  
  8.  
  9. /* Dichiarazione Funzioni*/
  10.  
  11. int main ()
  12. {
  13.     int i,              // var
  14.         j,              // var
  15.         lines,          // var
  16.         columns,        // var
  17.         **intMatrix;    // pointer
  18.  
  19.     printf("Type the matrix lines> ");
  20.     scanf("%d", &lines); /* add a validation */
  21.     printf("Type the matrix columns> ");
  22.     scanf("%d", &columns); /* add validation */
  23.  
  24.     intMatrix = (int **)malloc(lines * sizeof(int *));
  25.     //pointer to an array of [lines] pointers
  26.  
  27.     for (i = 0; i < lines; ++i)
  28.         intMatrix[i] = (int *)malloc(columns * sizeof(int));
  29.         //pointer to a single array with [columns] integers
  30.  
  31.     /* Adding var to matrix */
  32.     for (i = 0; i < lines; ++i)
  33.    
  34.         for (j = 0; j < columns; ++j)
  35.     {
  36.         printf("Type a number for <line: %d, column: %d>", i+1, j+1);
  37.         scanf("%d", &intMatrix[i][j]); // add validation
  38.     }
  39.     /* Print at video of matrix maded */
  40.     for (i = 0; i < lines; ++i)
  41.     {
  42.         for (j = 0; j < columns; ++j)
  43.         {
  44.             printf("Number: %d, < line: %d column: %d >\n", intMatrix[i][j], i+1, j+1);
  45.         }
  46.     }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement