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