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

8
stdout
1 2 3 4 5 6 7 8 
9 10 11 12 13 14 15 16 
17 18 19 20 21 22 23 24 
25 26 27 28 29 30 31 32