fork download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. //必要があれば変数などを追加してもOKです
  5.  
  6. int main(){
  7. int i,j,k=0;
  8. int a,b;
  9. int **mat;
  10. scanf("%d %d",&a,&b);
  11.  
  12. mat=malloc(a*sizeof(int*));
  13. for(i=0;i<a;i++)
  14. {mat[i]=malloc(b*sizeof(int));}
  15.  
  16. for(i=0;i<a;i++)
  17. {for(j=0;j<b;j++)
  18. {printf("%d ",mat[i][j]);}
  19. printf("\n");}
  20.  
  21.  
  22. for(i=0;i<a;i++)
  23. {for(j=0;j<b;j++)
  24. {mat[i][j]=k++;}
  25. }
  26.  
  27. free(mat);
  28.  
  29. return 0;
  30. }
  31.  
Success #stdin #stdout 0.01s 5320KB
stdin
3 2
stdout
0 0 
0 0 
0 0