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