C Number Pattern Programs

Beginner
6 min read
Updated: Nov 2026
3 examples
int + printf

Definition and Usage

A C number pattern is a program that prints integers in rows. The outer for loop chooses the row. The inner for loop prints each int with printf("%d", n), then printf("\n") ends that row.

%d 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 a field width such as %2d 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++)
        printf("%d", n);   /* digits, no space */
    printf("\n");          /* end the row */
}

How C Prints a Number

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

PieceCWhat it does
Digitprintf("%d", n);Prints the int with no extra space
Same digitprintf("%d", row);Repeats the row number on that line
Next valuevalue++Keeps counting across columns and rows
New rowprintf("\n");Finish the row
Widthprintf("%2d", n);Two columns, padded on the left
Odd or evenn % 20/1 patterns from the remainder
One digitputchar('0' + n);Works for 0–9, no format string

C Examples

Three 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
#include <stdio.h>

int main(void) {
    int rows = 5;

    for (int row = rows; row >= 1; row--) {
        for (int n = 1; n <= row; n++)
            printf("%d", n);
        printf("\n");
    }
    return 0;
}

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. printf("%d", n) prints the int; printf("\n") 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
#include <stdio.h>

int main(void) {
    int rows = 5;

    for (int row = 1; row <= rows; row++) {
        for (int col = 1; col <= row; col++)
            printf("%d", row);
        printf("\n");
    }
    return 0;
}

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 printf("%d", row) for printf("%d", col) and the line becomes 123.

Example 3 — Keep two-digit values aligned

%2d reserves two columns. The trailing space in the format separates them.

C
#include <stdio.h>

int main(void) {
    int value = 1;

    for (int row = 1; row <= 4; row++) {
        for (int col = 1; col <= row; col++) {
            printf("%2d ", value);
            value++;
        }
        printf("\n");
    }
    return 0;
}

How It Works

  1. value lives outside both loops, so counting continues on the next row.
  2. %2d prints 1 as two columns and leaves 10 as two digits.
  3. The space after %2d in the format string separates columns.

62 C Number Pattern Programs

Each card is a full C program: nested for loops, an int for the cell, and printf("%d", ...). 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

printf("%d", 10) prints the characters 1 and 0 with no space after them. The next printf starts immediately, so 10 and 11 become 1011. Print a space, or use a field width such as %2d, when values can be more than one digit.
printf("%d", n) prints the integer and stays on the same line. printf("\n") ends the row. Call it once after the inner loop.
Give every value the same width. printf("%2d", n) reserves two columns and pads on the left with spaces. printf("%2d ", n) adds a separating space after that width.
Yes, when the value is 0 through 9. putchar('0' + n) writes one character and needs no format string. printf("%d", n) still works, and it is the call you need once the value reaches 10.

Next: Number Pattern 1

A full C walkthrough of the descending number triangle, from the outer for through printf("\n").

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