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