Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //col 0 1 2 3
- //row 0 - 1 2 4 8
- //row 1 - 2 4 8 16
- //row 2 - 4 8 16 32
- //row 3 - 8 16 32 64
- let matN = +gets();
- let rows = matN;
- let cols = matN;
- let matrix = [];
- let sum = 0;
- for(let row = 0; row < rows; row++){
- matrix[row] = [];
- for(let col = 0; col < cols; col++){
- matrix[row][col] = 2**(row + col)
- }
- }
- console.log(matrix);
- for(let firstCount = matN - 1; firstCount > 0; firstCount--){
- for(let row = firstCount; row < matN; row++){
- for(let col = 0; col < matN; col++){
- if((row-col) === firstCount){
- sum = sum + (matrix[row][col]);
- }
- }
- }
- }
- console.log(sum);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement