fork download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. int main(void) {
  5. int row, column;
  6. int **D;
  7. scanf("%d",&row);
  8. scanf("%d",&column);
  9. D=(int**)malloc(sizeof(int)*row);
  10. if(D==NULL){
  11. printf("ERROR\n");
  12. return 0;
  13. }
  14. for(int i=0; i<row; i++){
  15. D[i]=(int*)malloc(sizeof(int)*column);
  16. if(D[i]==NULL){
  17. printf("ERROR\n");
  18. return 0;
  19. }
  20. }
  21.  
  22. int count=0;
  23. for(int i=0; i<row; i++){
  24. for(int j=0; j<column; j++){
  25. count++;
  26. D[i][j]=count;
  27. }
  28. }
  29.  
  30. for(int i=0; i<row; i++){
  31. for(int j=0; j<column; j++){
  32. printf("%d ", D[i][j]);
  33. }
  34. putchar('\n');
  35. }
  36.  
  37. for(int i=0; i<row; i++){
  38. free(D[i]);
  39. }
  40. free(D);
  41. return 0;
  42. }
  43.  
Success #stdin #stdout 0s 5288KB
stdin
2 3
stdout
1 2 3 
4 5 6