Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR C

how to scanf two dimensional array in c

#include <stdio.h>
#include <stdlib.h>

int main (int argc, char* arv[]){

  int target;               // for later processing, irrelevant here
  int m;                    // m = #rows and #columns of array
  int array[m][m];
  scanf("%d %d", &target, &m);
 
  int i, k;
  for(i = 0; i < m; i++){
    for(k = 0; k < m; k++){
       scanf("%d", &(array[i][k]));    // save value in array.
    }
  }
                                      // the problem occurs before this point.
  for(i = 0; i < m; i++){
     for(k = 0; k < m; k++){
       printf("%2d", array[i][k]);    // print array.
     }
     printf("
");
  }  

  return 0;
}
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #scanf #dimensional #array
ADD COMMENT
Topic
Name
8+1 =