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