Odd-Length Descending Number Pyramid in C

Beginner
⏱️ 6 min read
📚 Updated: Aug 2025
🎯 2 Code Examples
Math in Loops

What You’ll Learn

How to print an odd-length descending number pyramid in C. Each row prints numbers starting at 1, but the row length shrinks by 2 each line.

The key is the formula 2*i - 1, which produces odd row lengths like 7, 5, 3, and 1.

⭐ Pattern Output

For rows = 4, the pattern looks like this:

Output
1234567
12345
123
1
1

Complete C Program

The outer loop decreases the row size, and the inner loop prints from 1 up to 2*i - 1.

c
#include <stdio.h>

int main() {
    int rows = 4;
    int i, j;

    for (i = rows; i >= 1; --i) {
        for (j = 1; j <= (2 * i - 1); ++j) {
            printf("%d", j);
        }
        printf("\n");
    }

    return 0;
}
2

Variation — User Input Version

Accept the number of rows from the user:

c
#include <stdio.h>

int main() {
    int rows;
    int i, j;

    printf("Enter the number of rows: ");
    scanf("%d", &rows);

    for (i = rows; i >= 1; --i) {
        for (j = 1; j <= (2 * i - 1); ++j) {
            printf("%d", j);
        }
        printf("\n");
    }

    return 0;
}

Explore More Number Patterns

Try switching 2*i - 1 to 2*i for even-length rows, or reverse the outer loop for a growing pyramid.

All Number Patterns →
Did you know?

The sum of the first n odd numbers is . That’s why this pattern prints exactly rows² digits in total.

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.

12 people found this page helpful