Beginner

Print Simple Pyramid Pattern

Print pyramid of stars

This program prints a pyramid pattern of stars using nested loops. The outer loop controls rows, inner loops control spaces and stars.

Program Code

pyramid_star.c
C
1#include <stdio.h>
2
3int main() {
4 int rows;
5
6 printf("Enter number of rows: ");
7 scanf("%d", &rows);
8
9 for (int i = 1; i <= rows; i++) {
10 // Print spaces
11 for (int j = 1; j <= rows - i; j++) {
12 printf(" ");
13 }
14 // Print stars
15 for (int k = 1; k <= 2 * i - 1; k++) {
16 printf("*");
17 }
18 printf("\n");
19 }
20
21 return 0;
22}
Output

Enter number of rows: 5

*

***

*****

*******

*********

Pattern Analysis

RowSpacesStars
141
233
325
417
509

Want to Learn More?

Explore our comprehensive tutorials for in-depth explanations of C programming concepts.

Browse Tutorials
Back to All Examples