fork download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. int main(void){
  5. int a, b, i, j, k = 1;
  6. int **mat;
  7.  
  8. scanf("%d %d", &a, &b);
  9.  
  10. mat = (int **)malloc(sizeof(int *) * a);
  11.  
  12. for(i = 0; i < a; i++){
  13. mat[i] = (int *)malloc(sizeof(int) * b);
  14. }
  15.  
  16. for(i = 0; i < a; i++){
  17. for(j = 0; j < b; j++){
  18. mat[i][j] = k++;
  19. printf("%d ", mat[i][j]);
  20. }
  21. printf("\n");
  22. }
  23.  
  24. for(i = 0; i < a; i++){
  25. free(mat[i]);
  26. }
  27. free(mat);
  28.  
  29. return 0;
  30. }
Success #stdin #stdout 0s 5308KB
stdin
2 3
stdout
1 2 3 
4 5 6