Previous Next
0 / 33
Module DEMO-32-60DEMO-C-32

Square of Numbers (Repeating Rows)

DEMO-C-32 โ€ข Programming in C

Browser-only practice

Problem Statement

Write a program that reads an integer N and prints an N x N square of numbers.

Each row should contain the numbers from 1 to N, separated by spaces. All rows should be identical.


Requirements

  • Use nested loops to generate the output.
  • Each row must end with a newline character.
  • Numbers within a row must be separated by a single space.
  • You must not contain space at the end of each line

Constraints

You must use nested loops in your solution.

Input Format

A single integer N where 1 <= N <= 20.

Output Format

N rows, each containing numbers from 1 to N, separated by spaces.

Sample Testcases

Submit runs every public testcase in this browser. Results and code never leave this device.

Sample #1
Public sample
3
1 2 3
1 2 3
1 2 3
Input: 3
Sample #2
Public sample
6
1 2 3 4 5 6
1 2 3 4 5 6
1 2 3 4 5 6
1 2 3 4 5 6
1 2 3 4 5 6
1 2 3 4 5 6
Input: 6
Sample #3
Public sample
8
1 2 3 4 5 6 7 8
1 2 3 4 5 6 7 8
1 2 3 4 5 6 7 8
1 2 3 4 5 6 7 8
1 2 3 4 5 6 7 8
1 2 3 4 5 6 7 8
1 2 3 4 5 6 7 8
1 2 3 4 5 6 7 8
Input: 8

Web terminal

C, C++, Java, and Python run locally in a browser VM. No worker or visualizer is used.

Saved in this browser
Editor settings