paizaラーニングレベルアップ問題集の【2次元配列の表示】をやってみた。

paizaラーニングレベルアップ問題集の【2次元配列の表示】をやってみました。
- - -
##### 問題
###### 2*2の出力
https://paiza.jp/works/mondai/stdout_primer/stdout_primer__2dim_array_step1
###### 3*3の出力
https://paiza.jp/works/mondai/stdout_primer/stdout_primer__2dim_array_step2
###### 九九表の出力
https://paiza.jp/works/mondai/stdout_primer/stdout_primer__2dim_array_step3
###### N*Nの九九表の出力
https://paiza.jp/works/mondai/stdout_primer/stdout_primer__2dim_array_boss
- - -
##### C
###### 2*2の出力
```c
#include <stdio.h>
int main() {
	printf("%d %d\n", 0, 8);
	printf("%d %d\n", 1, 3);
	return 0;
}
```
###### 3*3の出力
```c
#include <stdio.h>

const int N = 3;

int main() {
	for (int i = 1; i <= N; i++) {
		int n;
		for (int j = 1; j < N; j++) {
			scanf("%d", &n);
			printf("%d ", n);
		}
		scanf("%d", &n);
		printf("%d\n", n);
	}
	return 0;
}
```
###### 九九表の出力
```c
#include <stdio.h>

const int N = 9;

int main() {
	for (int i = 1; i <= N; i++) {
		for (int j = 1; j < N; j++) {
			printf("%d ", i * j);
		}
		printf("%d\n", i * N);
	}
	return 0;
}
```
###### N*Nの九九表の出力
```c
#include <stdio.h>

int main() {
	int n;
	scanf("%d", &n);
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j < n; j++) {
			printf("%d ", i * j);
		}
		printf("%d\n", i * n);
	}
	return 0;
}
```
- - -
##### C++
###### 2*2の出力
```cpp
#include <iostream>
using namespace std;

int main() {
	cout << 0 << ' ' << 8 << endl;
	cout << 1 << ' ' << 3 << endl;
	return 0;
}
```
###### 3*3の出力
```cpp
#include <iostream>
using namespace std;

const int N = 3;

int main() {
	for (int i = 1; i <= N; i++) {
		int n;
		for (int j = 1; j < N; j++) {
			cin >> n;
			cout << n << ' ';
		}
		cin >> n;
		cout << n << endl;
	}
	return 0;
}
```
###### 九九表の出力
```cpp
#include <iostream>
using namespace std;

const int N = 9;

int main() {
	for (int i = 1; i <= N; i++) {
		for (int j = 1; j < N; j++) {
			cout << i * j << ' ';
		}
		cout << i * N << endl;
	}
	return 0;
}
```
###### N*Nの九九表の出力
```cpp
#include <iostream>
using namespace std;

int main() {
	int n;
	cin >> n;
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j < n; j++) {
			cout << i * j << ' ';
		}
		cout << i * n << endl;
	}
	return 0;
}
```
- - -
##### C#
###### 2*2の出力
```cs
using System;

class Program
{
	public static void Main()
	{
		Console.WriteLine(0 + " " + 8);
		Console.WriteLine(1 + " " + 3);
	}
}
```
###### 3*3の出力
```cs
using System;

class Program
{
	const int N = 3;
	
	public static void Main()
	{
		int[] n = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
		int k = 0;
		for (int i = 1; i <= N; i++) {
			for (int j = 1; j < N; j++) {
				Console.Write(n[k++] + " ");
			}
			Console.WriteLine(n[k++]);
		}
	}
}
```
###### 九九表の出力
```cs
using System;

class Program
{
	const int N = 9;
	
	public static void Main()
	{
		for (int i = 1; i <= N; i++) {
			for (int j = 1; j < N; j++) {
				Console.Write((i * j) + " ");
			}
			Console.WriteLine(i * N);
		}
	}
}
```
###### N*Nの九九表の出力
```cs
using System;

class Program
{
	public static void Main()
	{
		int n = int.Parse(Console.ReadLine());
		for (int i = 1; i <= n; i++) {
			for (int j = 1; j < n; j++) {
				Console.Write((i * j) + " ");
			}
			Console.WriteLine(i * n);
		}
	}
}
```
- - -
##### Go
###### 2*2の出力
```go
package main
import "fmt"

func main() {
	fmt.Println(0, 8)
	fmt.Println(1, 3)
}
```
###### 3*3の出力
```go
package main
import "fmt"

const N = 3

func main() {
	for i := 1; i <= N; i++ {
		var n int
		for j := 1; j < N; j++ {
			fmt.Scan(&n)
			fmt.Print(n, " ")
		}
		fmt.Scan(&n)
		fmt.Println(n)
	}
}
```
###### 九九表の出力
```go
package main
import "fmt"

const N = 9

func main() {
	for i := 1; i <= N; i++ {
		for j := 1; j < N; j++ {
			fmt.Print(i * j, " ")
		}
		fmt.Println(i * N)
	}
}
```
###### N*Nの九九表の出力
```go
package main
import "fmt"

func main() {
	var n int
	fmt.Scan(&n)
	for i := 1; i <= n; i++ {
		for j := 1; j < n; j++ {
			fmt.Print(i * j, " ")
		}
		fmt.Println(i * n)
	}
}
```
- - -
##### Java
###### 2*2の出力
```java
public class Main {
	public static void main(String[] args) {
		System.out.println(0 + " " + 8);
		System.out.println(1 + " " + 3);
	}
}
```
###### 3*3の出力
```java
import java.util.*;

public class Main {
	
	static final int N = 3;

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		for (int i = 1; i <= N; i++) {
			for (int j = 1; j < N; j++) {
				System.out.print(sc.nextInt() + " ");
			}
			System.out.println(sc.nextInt());
		}
		sc.close();
	}
}
```
###### 九九表の出力
```java
import java.util.*;

public class Main {

	static final int N = 9;
	
	public static void main(String[] args) {
		for (int i = 1; i <= N; i++) {
			for (int j = 1; j < N; j++) {
				System.out.print((i * j) + " ");
			}
			System.out.println(i * N);
		}
	}
}
```
###### N*Nの九九表の出力
```java
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		sc.close();
		for (int i = 1; i <= n; i++) {
			for (int j = 1; j < n; j++) {
				System.out.print((i * j) + " ");
			}
			System.out.println(i * n);
		}
	}
}
```
- - -
##### JavaScript
###### 2*2の出力
```js
console.log(0, 8);
console.log(1, 3);
```
###### 3*3の出力
```js
const N = 3;
const n = require("fs").readFileSync("/dev/stdin", "utf8").trim().split(' ').map(Number);
var k = 0;
for (var i = 1; i <= N; i++) {
	var s = n[k++];
	for (var j = 2; j <= N; j++) {
		s += ' ' + n[k++];
	}
	console.log(s);
}
```
###### 九九表の出力
```js
const N = 9;
for (var i = 1; i <= N; i++) {
	var s = i;
	for (var j = 2; j <= N; j++) {
		s += ' ' + (i * j);
	}
	console.log(s);
}
```
###### N*Nの九九表の出力
```js
const n = Number(require("fs").readFileSync("/dev/stdin", "utf8").trim());
for (var i = 1; i <= n; i++) {
	var s = i;
	for (var j = 2; j <= n; j++) {
		s += ' ' + (i * j);
	}
	console.log(s);
}
```
- - -
##### Kotlin
###### 2*2の出力
```kotlin
fun main() {
	println("" + 0 + ' ' + 8)
	println("" + 1 + ' ' + 3)
}
```
###### 3*3の出力
```kotlin
val N = 3

fun main() {
	val n = readLine()!!.split(' ').map { it.toInt() }
	var k = 0
	for (i in 1..N) {
		for (j in 1 until N) {
			print("" + n[k++] + ' ')
		}
		println(n[k++])
	}
}
```
###### 九九表の出力
```kotlin
val N = 9

fun main() {
	for (i in 1..N) {
		for (j in 1 until N) {
			print("" + (i * j) + ' ')
		}
		println(i * N)
	}
}
```
###### N*Nの九九表の出力
```kotlin
import java.util.*

fun main() {
	val sc = Scanner(System.`in`)
	val n = sc.nextInt()
	sc.close()
	for (i in 1..n) {
		for (j in 1 until n) {
			print("" + (i * j) + ' ')
		}
		println(i * n)
	}
}
```
- - -
##### PHP
###### 2*2の出力
<?php
	echo 0, ' ', 8, PHP_EOL;
	echo 1, ' ', 3, PHP_EOL;
?>
###### 3*3の出力
<?php
	$N = 3;
	$n = array_map("intval", explode(' ', trim(fgets(STDIN))));
	$k = 0;
	for ($i = 1; $i <= $N; $i++) {
		for ($j = 1; $j < $N; $j++) {
			echo $n[$k++], ' ';
		}
		echo $n[$k++], PHP_EOL;
	}
?>
###### 九九表の出力
<?php
	$N = 9;
	for ($i = 1; $i <= $N; $i++) {
		for ($j = 1; $j < $N; $j++) {
			echo ($i * $j), ' ';
		}
		echo ($i * $N), PHP_EOL;
	}
?>
###### N*Nの九九表の出力
```php
<?php
	$n = intval(trim(fgets(STDIN)));
	for ($i = 1; $i <= $n; $i++) {
		for ($j = 1; $j < $n; $j++) {
			echo ($i * $j), ' ';
		}
		echo ($i * $n), PHP_EOL;
	}
?>
```
- - -
##### Perl
###### 2*2の出力
```pl
print 0, ' ', 8, $/;
print 1, ' ', 3, $/;
```
###### 3*3の出力
```pl
my $N = 3;
my @n = map { int($_) } split(' ', <STDIN>);
my $k = 0;
for (my $i = 1; $i <= $N; $i++) {
	for (my $j = 1; $j < $N; $j++) {
		print "$n[$k++] ";
	}
	print "$n[$k++]$/";
}
```
###### 九九表の出力
```pl
my $N = 9;
for (my $i = 1; $i <= $N; $i++) {
	for (my $j = 1; $j < $N; $j++) {
		print $i * $j, ' ';
	}
	print $i * $N, $/;
}
```
###### N*Nの九九表の出力
```pl
chomp(my $n = <STDIN>);
for (my $i = 1; $i <= $n; $i++) {
	for (my $j = 1; $j < $n; $j++) {
		print $i * $j, ' ';
	}
	print $i * $n, $/;
}
```
- - -
##### Python3
###### 2*2の出力
```py
print(0, 8)
print(1, 3)
```
###### 3*3の出力
```py
N = 3
n = list(map(int, input().split()))
k = 0
for i in range(0, N):
	s = str(n[k])
	k += 1
	for j in range(1, N):
		s += ' ' + str(n[k])
		k += 1
	print(s)
```
###### 九九表の出力
```py
N = 9
for i in range(1, N + 1):
	s = str(i)
	for j in range(2, N + 1):
		s += ' ' + str(i * j)
	print(s)
```
###### N*Nの九九表の出力
```py
n = int(input())
for i in range(1, n + 1):
	s = str(i)
	for j in range(2, n + 1):
		s += ' ' + str(i * j)
	print(s)
```
- - -
##### Ruby
###### 2*2の出力
```rb
print 0, ' ', 8, "\n";
print 1, ' ', 3, "\n";
```
###### 3*3の出力
```rb
N = 3
n = gets.split.map(&:to_i)
k = 0
N.times do
	(N-1).times do
		print n[k], ' '
		k += 1
	end
	puts n[k]
	k += 1
end		
```
###### 九九表の出力
```rb
N = 9
(1..N).each do |i|
	(1...N).each do |j|
		print i * j, ' '
	end
	puts i * N
end
```
###### N*Nの九九表の出力
```rb
N = gets.to_i
(1..N).each do |i|
	(1...N).each do |j|
		print i * j, ' '
	end
	p i * N
end
```
- - -
##### Scala
###### 2*2の出力
```scala
import scala.io.StdIn._

object Main extends App{
	println("" + 0 + ' ' + 8)
	println("" + 1 + ' ' + 3)
}
```
###### 3*3の出力
```scala
import scala.io.StdIn._

object Main extends App{
	val N = 3
	val n = readLine().split(' ').map { _.toInt }
	var k = 0
	for (i <- 1 to N) {
		for (j <- 1 until N) {
			print("" + n(k) + ' ')
			k += 1
		}
		println(n(k))
		k += 1
	}
}
```
###### 九九表の出力
```scala
import scala.io.StdIn._

object Main extends App{
	val N = 9
	for (i <- 1 to N) {
		for (j <- 1 until N) {
			print("" + (i * j) + ' ')
		}
		println(i * N)
	}
}
```
###### N*Nの九九表の出力
```scala
import scala.io.StdIn._

object Main extends App{
	val n = readInt()
	for (i <- 1 to n) {
		for (j <- 1 until n) {
			print("" + (i * j) + ' ')
		}
		println(i * n)
	}
}
```
- - -
##### Swift
###### 2*2の出力
```swift
print(0, 8)
print(1, 3)
```
###### 3*3の出力
```swift
let N = 3
let n = readLine()!.split(separator: " ").compactMap { Int($0) }
var k = 0
for _ in 1...N {
	var s = String(n[k])
	k += 1
	for _ in 1..<N {
		s += " " + String(n[k])
		k += 1
	}
	print(s)
}
```
###### 九九表の出力
```swift
let N = 9
for i in 1...N {
	var s = String(i)
	for j in 2...N {
		s += " " + String(i * j)
	}
	print(s)
}
```
###### N*Nの九九表の出力
```swift
let n = Int(readLine()!)!
for i in 1...n {
	var s = String(i)
	for j in 2...n {
		s += " " + String(i * j)
	}
	print(s)
}
```