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

stdout
1 2 3 4 5 6 
7 8 9 10 11 12 
13 14 15 16 17 18 
19 20 21 22 23 24 
25 26 27 28 29 30