Search
 
SCRIPT & CODE EXAMPLE
 

CPP

fill a two dimensional array with default value

for (double[] row: matrix)
    Arrays.fill(row, 1.0);
Comment

fill two dimensional array

//this way u can fill your array row by row

Scanner input = new Scanner(System.in);
for (int i = 0; i < row; i++){
	for (int j = 0; j < column; j++){
        array[i][j] = input.nextInt();
	}
}

//this way u can fill your array column by column
//Scanner input = new Scanner(System.in);
for (int i = 0; i < column; i++){
	for (int j = 0; j < row; j++){
        array[i][j] = input.nextInt();
	}
}
Comment

Fill 2-dimensional array with value

int a[100000][100000];
std::fill((int*)a,(int*)a+sizeof(a)/sizeof(int),0);
Comment

Fill two dimensional array

// To fill two dimenional array with some simbol, e.g. "*"
Scanner scanner = new Scanner(System.in);
int number = scanner.nextInt();

String[][] matrix = new String[number][number];

for (String[] strings : matrix) {
    Arrays.fill(strings, ".");
}

// To modify only middle and/or diagonales:
for (int i = 0; i < matrix.length; i++) {
    for (int j = 0; j < matrix[i].length; j++) {
        if (i == number / 2) {
            matrix[i][j] = "*";
        }
        if (j == number / 2) {
            matrix[i][j] = "*";
        }
        if (i == j) {
            matrix[i][j] = "*";
        }
        if (i == number - j - 1) {
            matrix[i][j] = "*";
        }
    }
}

/*

Result:
* . . * . . * 
. * . * . * . 
. . * * * . . 
* * * * * * * 
. . * * * . . 
. * . * . * . 
* . . * . . * 

*/
Comment

PREVIOUS NEXT
Code Example
Cpp :: c++ to mips assembly converter 
Cpp :: variadic template constructor matches better than copy constructor 
Cpp :: loops in c++ with example 
Cpp :: facade pattern C++ code 
Cpp :: what does npl mean? 
Cpp :: omp multiple reductions 
Cpp :: go to particular place in vector using iterator 
Cpp :: C++ singleton prevent copy 
Cpp :: ue4 c++ bool to text 
Cpp :: how are c++ references implemented 
Cpp :: C++ (.NET CLI) 
Cpp :: C++ Vector Initialization method 01 
Cpp :: c++ thread id 
Cpp :: 28+152+28+38+114 
Cpp :: create a table using pointers in C++ 
Cpp :: how to writte comment in c++ 
Cpp :: generate random ints and floats 
Cpp :: c++ caps lock key 
Cpp :: an array that take different data type c++ 
Cpp :: multiple objects in vector C++ 
Cpp :: pass address to function c++ 
Cpp :: simplest code for stack implementation in c++ 
Cpp :: how to find total numbe of distinct characters in a string in c 
Cpp :: c++ calorie calculator using a for loop 
Cpp :: operator using 
Cpp :: how to read qlistwidget in c++ 
Cpp :: onactorbeginoverlap c++ 
Cpp :: lcm recursive program in c++ 
Cpp :: c++ projects 
Cpp :: concatenate 2 vectors in c++ 
ADD CONTENT
Topic
Content
Source link
Name
8+8 =