C Program to Print Number Patterns Using Nested Loops

Written: August 15, 2026

Number patterns are nested-loop drills with visible structure: rows outside, columns inside.

This walkthrough keeps the logic small and readable so you can type it, run it, and then change one input at a time to see what happens.

What you will build

Print a right triangle where row i shows numbers 1..i.

  • Read number of rows
  • Outer loop for row i
  • Inner loop print 1..i
  • Newline after each row

Working C example

include <stdio.h>

int main(void) {
    int rows, i, j;
    printf("Enter rows: ");
    if (scanf("%d", &rows) != 1 || rows < 1) return 1;
    for (i = 1; i <= rows; i++) {
        for (j = 1; j <= i; j++) {
            printf("%d ", j);
        }
        printf("\n");
    }
    return 0;
}

Advertisement

How the logic works

Read the program top to bottom: includes and main first, then the statements that change variables, then the print that proves the result.

If your output looks wrong, print the variables before and after the critical lines. That single habit catches most beginner bugs faster than rewriting the whole file.

Change the inner print to i instead of j for a repeated-number triangle variant.

Advertisement

Keep learning

If this walkthrough on C Program to Print Number Patterns Using Nested Loops helped, open the code again and change one input or assumption. Small experiments beat rereading the same example.

Want more step-by-step tutorials like this? Browse blog.xqa.io — and tell us which topic you want next.

Advertisement

Previous Article

JavaScript Function Declaration vs Function Expression

Next Article

C Program to Check Character Type

Write a Comment

Leave a Comment

Your email address will not be published. Required fields are marked *

Subscribe to our Newsletter

Subscribe to our email newsletter to get the latest posts delivered right to your email.
Pure inspiration, zero spam ✨