C# Number Pattern Programs

Beginner
6 min read
Updated: Nov 2026
3 examples
int + Console.Write

Definition and Usage

A C# number pattern is a console program that prints integers in rows. The outer for loop chooses the row. The inner for loop prints each int with Console.Write, then Console.WriteLine ends that row.

Console.Write(n) prints the decimal digits of n and stays on the line. Single digits sit next to each other (123). Once a value reaches 10, add a space or call PadLeft so 10 and 11 do not become 1011.

The loop variable is the number.

Print col for 1, 2, 3… Print row to repeat the same digit. A separate int value that you increment is how running sequences cross from one row to the next.

C# Syntax

Count the outer loop down when the first row should be the longest. The inner loop still walks 1 through the current width.

C#
for (int row = rows; row >= 1; row--)
{
    for (int n = 1; n <= row; n++)
        Console.Write(n);    // digits, no space
    Console.WriteLine();    // end the row
}

How C# Prints a Number

Map each part of the console shape to a C# type or call.

PieceC#What it does
DigitConsole.Write(n)Prints the int with no extra space
Same digitConsole.Write(row)Repeats the row number on that line
Next valuevalue++Keeps counting across columns and rows
New rowConsole.WriteLine()Finish the row
Widthn.ToString().PadLeft(2)Two-digit columns stay aligned
Odd or evenn % 20/1 patterns from the remainder
One callstring.Join("", Enumerable.Range(1, row))Same 1…row string without an inner loop

C# Examples

Three console programs. Each one changes only the C# that chooses the int or its width.

Example 1 — Shrink the row with the outer loop

Start row at 5 and stop at 1. The inner loop prints 1 through row.

C#
using System;

class DescendTriangle
{
    static void Main()
    {
        int rows = 5;

        for (int row = rows; row >= 1; row--)
        {
            for (int n = 1; n <= row; n++)
                Console.Write(n);
            Console.WriteLine();
        }
    }
}

How It Works

  1. row-- makes each later line one digit shorter.
  2. The inner for always restarts at 1, so every row begins with 1.
  3. Console.Write(n) prints the int; WriteLine ends the row.

Example 2 — Print the row number, not the column

The inner loop only decides how many times to print. The value is row.

C#
using System;

class RepeatRow
{
    static void Main()
    {
        int rows = 5;

        for (int row = 1; row <= rows; row++)
        {
            for (int col = 1; col <= row; col++)
                Console.Write(row);
            Console.WriteLine();
        }
    }
}

How It Works

  1. Row 1 runs the inner loop once and prints 1.
  2. Row 3 runs it three times and prints 3 each time.
  3. Swap Console.Write(row) for Console.Write(col) and the line becomes 123.

Example 3 — Keep two-digit values aligned

PadLeft(2) gives every number the same width before the space.

C#
using System;

class PaddedCounter
{
    static void Main()
    {
        int value = 1;

        for (int row = 1; row <= 4; row++)
        {
            for (int col = 1; col <= row; col++)
            {
                Console.Write(value.ToString().PadLeft(2));
                Console.Write(' ');
                value++;
            }
            Console.WriteLine();
        }
    }
}

How It Works

  1. value lives outside both loops, so counting continues on the next row.
  2. ToString().PadLeft(2) turns 1 into " 1" and leaves "10" as two characters.
  3. The extra Console.Write(' ') separates columns.

62 C# Number Pattern Programs

Each card is a full console program: nested for loops, an int for the cell, and Console.Write. Open one for the walkthrough.

Number Pattern 1
Number Pattern 2
Number Pattern 3
Number Pattern 4
Number Pattern 5
Number Pattern 6
Number Pattern 7
Number Pattern 8
Number Pattern 9
Number Pattern 10
Number Pattern 11
Number Pattern 12
Number Pattern 13
Number Pattern 14
Number Pattern 15
Number Pattern 16
Number Pattern 17
Number Pattern 18
Number Pattern 19
Number Pattern 20
Number Pattern 21
Number Pattern 22
Number Pattern 23
Number Pattern 24
Number Pattern 25
Number Pattern 26
Number Pattern 27
Number Pattern 28
Number Pattern 29
Number Pattern 30
Number Pattern 31
Number Pattern 32
Number Pattern 33
Number Pattern 34
Number Pattern 35
Number Pattern 36
Number Pattern 37
Number Pattern 38
Number Pattern 39
Number Pattern 40
Number Pattern 41
Number Pattern 42
Number Pattern 43
Number Pattern 44
Number Pattern 45
Number Pattern 46
Number Pattern 47
Number Pattern 48
Number Pattern 49
Number Pattern 50
Number Pattern 51
Number Pattern 52
Number Pattern 53
Number Pattern 54
Number Pattern 55
Number Pattern 56
Number Pattern 57
Number Pattern 58
Number Pattern 59
Number Pattern 60
Number Pattern 61
Number Pattern 62

Frequently Asked Questions

Console.Write(10) prints the characters 1 and 0 with no space after them. The next Write starts immediately, so 10 and 11 become 1011. Print a space, or use PadLeft, when values can be more than one digit.
Console.Write prints and stays on the same line, which is how each number in a row is placed. Console.WriteLine ends the row. Call WriteLine once after the inner loop.
Give every value the same width. value.ToString().PadLeft(2) pads on the left with spaces. Composite format Console.Write("{0,3}", value) does the same with a width of 3.
Yes. Console.WriteLine(string.Join("", Enumerable.Range(1, row))) prints 1 through row as one string. Nested for loops are what these programs teach; Enumerable.Range is a shortcut once the shape is clear.

Next: Number Pattern 1

A full C# walkthrough of the descending number triangle, from the outer for through Console.WriteLine.

Number Pattern 1 →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

28 people found this page helpful