Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Problem 9. Matrix of Numbers
- //
- // Write a program that reads from the console a positive integer
- // number n (1 ≤ n ≤ 20) and prints a matrix like in the examples below.
- // Use two nested loops.
- //
- // Examples:
- // n matrix
- // 2 1 2
- // 2 3
- //
- // n matrix
- // 3 1 2 3
- // 2 3 4
- // 3 4 5
- //
- // n matrix
- // 4 1 2 3 4
- // 2 3 4 5
- // 3 4 5 6
- // 4 5 6 7
- let input = ['3'];
- let print = this.print || console.log;
- let gets = this.gets || ((arr, index) => () => arr[index++])(input, 0)
- let num = +gets();
- let matrix = '';
- let counter = 0;
- for(let i = 1; i <= num; i++){
- for (let i = 1; i < num + 1; i++){
- matrix += counter + i;
- }
- counter += 1;
- console.log(matrix);
- matrix = '';
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement