A left-shifted descending number triangle prints digits i..rows on each row, so every line starts one digit higher and the left edge appears to slide right.
Remember
Rule: for i = 1..n, print i..n
12345
2345
345
45
5 ← 5 rows
In C# the outer loop picks the row start i, the inner loop prints j from i to rows, then Console.WriteLine() moves to the next line. Compare with Program 1, which prints 1..i while counting the outer loop down.
Approach
How to Solve It
Two ways to emit the same shape — start with nested loops, then optionally shorten with LINQ.
Method
Idea
Best for
Nested loops
Outer = start 1..n, inner = digits i..n via Write
Learning, interviews, exams
Enumerable.Range
Build a whole digit row in one call
Shorter demos once loops click
Pseudocode
Pseudocode
for i from 1 to rows:
for j from i to rows:
print j (no newline)
print newline
Cheat sheet
Goal
Pattern
Pick row start
for (i = 1; i <= rows; i++)
Print digits i..rows
for (j = i; j <= rows; j++) Console.Write(j);
End the row
Console.WriteLine();
One-line row shortcut
Console.WriteLine(string.Join("", Enumerable.Range(i, rows - i + 1)));
Program 1 shape instead
for (i = rows; i >= 1; i--) with j = 1..i
Write vs WriteLine
API
Effect
Use for
Console.Write
Stays on the same line
Each digit j
Console.WriteLine
Ends the current line
After the inner loop
Try it
Live Preview
Change the row count and the left-shifted triangle updates instantly — including the total digit count.
Whole numbers from 1 to 9 (keeps digits single-width). Tap a chip or type a value — the preview redraws as you go.
Live result5 rows · 15 digits
12345
2345
345
45
5
Trace
Worked Walkthrough — rows = 4
Trace each outer-loop value of i and the digits the inner loop prints.
i
Inner j
Printed row
Digits
1
1..4
1234
4
2
2..4
234
3
3
3..4
34
2
4
4..4
4
1
Total digits are 4+3+2+1 = 10 — the triangular number n(n+1)/2.
Code
C# Programs
Three complete programs: fixed height, row-count input, and a LINQ shortcut. Use View Output for sample results.
Example 1 — Fixed rows = 5
Outer loop picks the start digit; inner loop prints from i through rows.
C#
using System;
namespace MyApp
{
class Program
{
static void Main(string[] args)
{
int rows = 5;
int i, j;
for (i = 1; i <= rows; i++)
{
for (j = i; j <= rows; j++)
{
Console.Write(j);
}
Console.WriteLine();
}
}
}
}
Output
12345
2345
345
45
5
How It Works
1. Pick the start.for (i = 1; i <= rows; i++) yields 1, 2, 3, 4, 5 as row starts.
2. Print digits. When i = 1, the inner loop prints 12345; when i = 5, just 5.
3. Newline.WriteLine() after the inner loop starts the next shorter row.
Example 2 — User Input
Read the row count at runtime. Prefer int.TryParse in real apps so bad input does not throw.
C#
using System;
namespace MyApp
{
class Program
{
static void Main(string[] args)
{
int rows;
int i, j;
Console.Write("Enter the number of rows: ");
if (!int.TryParse(Console.ReadLine(), out rows) || rows < 1)
{
Console.WriteLine("Please enter a positive whole number.");
return;
}
for (i = 1; i <= rows; i++)
{
for (j = i; j <= rows; j++)
{
Console.Write(j);
}
Console.WriteLine();
}
}
}
}
2. Same nested loops. Four rows start at 1234 and end at 4.
Example 3 — LINQ Shortcut
Build each row with Enumerable.Range, then print it in one call.
C#
using System;
using System.Linq;
namespace MyApp
{
class Program
{
static void Main(string[] args)
{
int rows = 5;
for (int i = 1; i <= rows; i++)
{
Console.WriteLine(string.Join("", Enumerable.Range(i, rows - i + 1)));
}
}
}
}