Advertisement
Guest User

buildMatrixCMalloc

a guest
Feb 21st, 2020
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.72 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. void main(){
  5.     int row,col;
  6.     printf("Matrix Execrise\n");
  7.     printf("###############\n");
  8.     printf("Enter Cols Size: ");
  9.     scanf("%d",&col);
  10.     printf("Enter Rows Size:");
  11.     scanf("%d",&row);
  12.     printf("Build Matrix...\n");
  13.     int **mat = (int **)malloc(sizeof(int*)*row);
  14.     int i,j;
  15.     for(i=0;i<row;i++){
  16.         mat[i]=(int *)malloc(sizeof(int)*col);
  17.     }
  18.     printf("Reset Matrix...\n");
  19.     for(i=0;i<row;i++){
  20.         for(j=0;j<col;j++){
  21.             mat[i][j]=0;
  22.         }
  23.     }
  24.     printf("Print Matrix...\n");
  25.     for(i=0;i<row;i++){
  26.         for(j=0;j<col;j++){
  27.             printf(" %d",mat[i][j]);
  28.         }
  29.         printf("\n");
  30.     }
  31.    
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement