fork download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4.  
  5. int main(){
  6. int i,j,k;
  7. int a,b;
  8. int **mat;
  9. scanf("%d %d",&a,&b);
  10.  
  11. int c=1;
  12.  
  13. mat=(int**)malloc(sizeof(int*)*a);
  14. if(mat==NULL){
  15. printf("ERROR\n");
  16. return 0;
  17. }
  18.  
  19. for(i=0;i<a;i++){
  20. mat[i]=(int*)malloc(sizeof(int)*b);
  21. if(mat[i]==NULL){
  22. printf("ERROR\n");
  23. return 0;
  24. }
  25. }
  26.  
  27. for(i=0;i<a;i++){
  28. for(j=0;j<b;j++){
  29. mat[i][j]=c++;
  30. }
  31. }
  32.  
  33. for(i=0;i<a;i++){
  34. for(j=0;j<b;j++){
  35. printf("%d ",mat[i][j]);
  36. }
  37. printf("\n");
  38. }
  39.  
  40. for(i=0;i<a;i++){
  41. free(mat[i]);
  42. }
  43. free(mat);
  44.  
  45. return 0;
  46. }
  47.  
Success #stdin #stdout 0s 5348KB
stdin
3
2
stdout
1 2 
3 4 
5 6