Tutte le sfide
Facile 0 risolte 0% di accettazione

Multiplication Grid

Build a full multiplication table.

Problema

Build an n × n multiplication table: the value in row i, column j (both counting from 1) is i × j.

Implement multiplication_grid(n).

Input

n: The table size.

Output

Return the table as a list of rows.

Vincoli

0 ≤ n ≤ 20

Esempi

Esempio 1
Input:
n = 3

Output atteso:
expected = [
    [1, 2, 3],
    [2, 4, 6],
    [3, 6, 9]
]
Input:
long long n = 3;

Output atteso:
std::vector<std::vector<long long>> expected = {
    {1, 2, 3},
    {2, 4, 6},
    {3, 6, 9}
};
Input:
long n = 3;

Output atteso:
long[][] expected = new long[][] {
    new long[] {1, 2, 3},
    new long[] {2, 4, 6},
    new long[] {3, 6, 9}
};

Spiegazione

Rows are [1, 2, 3], [2, 4, 6] and [3, 6, 9].

Esempio 2
Input:
n = 1

Output atteso:
expected = [
    [1]
]
Input:
long long n = 1;

Output atteso:
std::vector<std::vector<long long>> expected = {
    {1}
};
Input:
long n = 1;

Output atteso:
long[][] expected = new long[][] {
    new long[] {1}
};

Spiegazione

A 1×1 table holds only 1 × 1 = 1.

Riferimenti

Questa sfida è adattata per CodeUtility. Segui la traccia e i vincoli sopra.

Impara dagli altri

Soluzioni della community

Nessuna soluzione pubblicata. Risolvi questa sfida per condividere la prima.