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