Triangle of numbers - MATLAB Cody - MATLAB Central

Problem 44457. Triangle of numbers

Difficulty:Rate

Create a matrix with the integers from 1 to n arranged in a triangular shape.

Every row i of the matrix contains i integers, and the rest of the elements are zeros.

Examples:

Input:  n = 6
Output: mat = [1 0 0
               2 3 0
               4 5 6]
Input:  n = 12
Output: mat = [1  0  0  0 
               2  3  0  0 
               4  5  6  0 
               7  8  9  10
               11 12 0  0]

Solution Stats

47.91% Correct | 52.09% Incorrect
Last Solution submitted on Sep 14, 2025

Problem Comments

Solution Comments

Show comments
AI Is Transforming Engineering Workflows
It’s an honor to deliver the keynote at MATLAB EXPO 2025. I'll...
0
MATLAB EXPO 2025 Registration is Now Open! November 12 – 13, 2025
Registration is now open for MathWorks annual virtual event MATLAB EXPO 2025...
0

Problem Recent Solvers330

Suggested Problems

More from this Author25

Problem Tags

Community Treasure Hunt

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

Start Hunting!