006-002-007

Nested Loop: Multiplication Table

Medium

Problem Description

Nested Loop: Multiplication Table

In this problem, you will read an integer n from standard input and create a program that uses nested loops (a for loop inside another for loop) to calculate every product in the multiplication table from group 1 through group n (each multiplied by 1 through n) and displays the result to standard output.

Learning Objective: Understand how to generate two-dimensional patterns using nested loops

Overview

Create a program that outputs a multiplication table. The outer loop handles "multiplication groups" and the inner loop handles "calculations within each group".

Input

n
  • n: the size of the multiplication table (positive integer)

Specifications

  • Output groups from 1 to n in order
  • In each group, perform multiplication from 1 to n
  • Output format: "[group] x [number] = [result]"
  • Separate each calculation result with a newline

Input/Output Example

Input:

3

Output:

1 x 1 = 1
1 x 2 = 2
1 x 3 = 3
2 x 1 = 2
2 x 2 = 4
2 x 3 = 6
3 x 1 = 3
3 x 2 = 6
3 x 3 = 9

Ready to Try Running Code?

Log in to access the code editor and execute your solutions for this problem.

Don't have an account?

Sign Up