fork download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. //必要があれば変数などを追加してもOKです
  5.  
  6. int main(){
  7. int i,j,k=1;
  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. {mat[i][j]=k++;}
  19. }
  20. for(i=0;i<a;i++)
  21. {for(j=0;j<b;j++)
  22. {printf("%d ",mat[i][j]);}
  23. printf("\n");}
  24.  
  25.  
  26. free(mat);
  27.  
  28. return 0;
  29. }
  30.  
Success #stdin #stdout 0.01s 5316KB
stdin
3 2
stdout
1 2 
3 4 
5 6