fork download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. int main(){
  5. int i,j,k;
  6. int a,b;
  7. int count = 1;
  8. int **mat;
  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. for(i = 0; i < a; i++){
  17. for(j = 0; j < b; j++){
  18. mat[i][j] = count++;
  19. }
  20. }
  21.  
  22. for(i=0;i<a;i++){
  23. for(j=0;j<b;j++){
  24. printf("%d ",mat[i][j]);
  25. }
  26. printf("\n");
  27. }
  28.  
  29. for(i = 0; i < a; i++){
  30. free(mat[i]);
  31. }
  32. free(mat);
  33.  
  34. return 0;
  35. }
Success #stdin #stdout 0s 5316KB
stdin
Standard input is empty
stdout
Standard output is empty