fork download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. int main(void){
  5. int *arr;
  6. unsigned int row = 3, col = 3,i, j, k;
  7. int l = 0;
  8.  
  9.  
  10. arr = calloc(sizeof( *arr ), sizeof *arr * row * col);
  11. if(arr == NULL){
  12. printf("Error, malloc\n");
  13. exit(3);
  14. }
  15.  
  16. for ( i = 0; i < row ; i++){
  17. for ( j = 0 ; j < col ; j++){
  18. arr[i * col + j] = l;
  19. l++;
  20. }
  21. }
  22.  
  23. for (k = 0 ; k < (row * col) ; k++){
  24. printf("%d ",arr[k]);
  25. }
  26.  
  27. free(arr);
  28. }
Success #stdin #stdout 0s 4348KB
stdin
Standard input is empty
stdout
0 1 2 3 4 5 6 7 8