Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVA

fill two dimensional array c++

//this way you can fill your array row by row
for (int i = 0; i < row; i++){
	for (int j = 0; j < column; j++){
		cin >> x;
        array[i][j] = x;
	}
}

//	[ 1 2 3 ]
//	[ 4 5 6 ]
//	[ 7 8 9 ]

//this way you can fill your array column by column

for (int i = 0; i < column; i++){
	for (int j = 0; j < row; j++){
		cin >> x;
        array[i][j] = x;
	}
}

// [ 1 4 7 ]
// [ 2 5 8 ]
// [ 3 6 9 ]
 
PREVIOUS NEXT
Tagged: #fill #dimensional #array
ADD COMMENT
Topic
Name
1+2 =