Given n, construct a matrix as shown in the example below.

Example

For n=8, the output should look like this:

 1 2 3 4 0 0 0 0
 1 2 3 4 0 0 0 0
 1 2 3 4 0 0 0 0
 1 2 3 4 0 0 0 0
 0 0 0 0 4 3 2 1
 0 0 0 0 4 3 2 1
 0 0 0 0 4 3 2 1
 0 0 0 0 4 3 2 1

Solution Stats

473 Solutions

278 Solvers

Last Solution submitted on Jul 06, 2026

Last 200 Solutions

Problem Comments

Solution Comments

Show comments
Loading...

Problem Recent Solvers278

Suggested Problems

More from this Author21

Problem Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!