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