C Programming/C Loop Statement

C Pattern Part 1 (Exercise)

Updated on January 9, 2026
2 min read

Pattern Printing Using Loop

Pattern programs print shapes (stars, numbers, characters) using loops.

They help you understand:

  • Nested loops
  • Row–column logic
  • Loop control

Basic Rule (Very Important)

  • Outer loop → controls rows
  • Inner loop → controls columns

1. Star Square Pattern

Pattern

* * *
* * *
* * *

Program

c
1#include <stdio.h>
2
3int main() {
4    int i, j;
5    for (i = 1; i <= 3; i++) {
6        for (j = 1; j <= 3; j++) {
7            printf("* ");
8        }
9        printf("\n");
10    }
11    return 0;
12}

2. Right Triangle Star Pattern

Pattern

*
* *
* * *
* * * *

Program

c
1#include <stdio.h>
2int main() {
3    int i, j;
4
5    for (i = 1; i <= 4; i++) {
6        for (j = 1; j <= i; j++) {
7            printf("* ");
8        }
9        printf("\n");
10    }
11    return 0;
12}

3. Inverted Right Triangle

Pattern

* * * *
* * *
* *
*

Program

c
1#include <stdio.h>
2
3int main() {
4    int i, j;
5
6    for (i = 4; i >= 1; i--) {
7        for (j = 1; j <= i; j++) {
8            printf("* ");
9        }
10        printf("\n");
11    }
12    return 0;
13}

4. Number Triangle Pattern

Pattern

1
1 2
1 2 3
1 2 3 4

Program

c
1#include <stdio.h>
2
3int main() {
4    int i, j;
5
6    for (i = 1; i <= 4; i++) {
7        for (j = 1; j <= i; j++) {
8            printf("%d ", j);
9        }
10        printf("\n");
11    }
12    return 0;
13}

How to Think in Pattern Questions

  1. Count rows
  2. Count columns per row
  3. Decide what to print (*ji)
  4. Use nested loops

Exam Tips

  • Pattern programs always use nested loops
  • Outer loop = number of lines
  • Inner loop = items per line
  • Very common in viva and written exams
C Pattern Part 1 (Exercise) | C Programming | Learn Syntax