0% found this document useful (0 votes)
48 views

Simple Pyramid Star Pattern

This document explains how to print a hollow pyramid or equilateral triangle star pattern in C. It first ignores trailing spaces to show the basic pattern structure. It then notes that each row contains 2*rownumber - 1 characters and stars are printed when the row or column equals the number of rows or when the column equals 2*rownumber - 1. Finally, it provides the C code to print the trailing spaces and the hollow pyramid pattern by conditionally printing stars or spaces depending on the row and column.

Uploaded by

Pragya Pandya
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
48 views

Simple Pyramid Star Pattern

This document explains how to print a hollow pyramid or equilateral triangle star pattern in C. It first ignores trailing spaces to show the basic pattern structure. It then notes that each row contains 2*rownumber - 1 characters and stars are printed when the row or column equals the number of rows or when the column equals 2*rownumber - 1. Finally, it provides the C code to print the trailing spaces and the hollow pyramid pattern by conditionally printing stars or spaces depending on the row and column.

Uploaded by

Pragya Pandya
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

At first glance the pattern may seem to be difficult but trust me if you are done with simple pyramid

star
pattern then there won't be much difficulty doing this. To make this pattern easy first of all lets ignore
the trailing spaces. If you ignore the trailing spaces the pattern would look like:
*
* *
* *
* *
*********
which is a normal hollow equilateral triangle star pattern. Here each row contains total 2*rownumber -
1 characters (including both inside spaces and stars). And here star only gets printed
when row=n or column=1 or column= (2*rownumber - 1) (where n is the total number of rows). And
inside spaces gets printed when stars don't.

Now, printing trailing spaces isn't difficult we just need to print n - rownumber spaces per row
(where n is the total number of rows to be printed).
/**
* C program to print hollow pyramid or hollow equilateral triangle star
pattern
*/

#include <stdio.h>

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

//Reads number of rows to be printed from user


printf("Enter value of n : ");
scanf("%d", &n);

for(i=1; i<=n; i++)


{
//Prints trailing spaces
for(j=i; j<n; j++)
{
printf(" ");
}

//Prints hollow pyramid


for(j=1; j<=(2*i-1); j++)
{
if(i==n || j==1 || j==(2*i-1))
{
printf("*");
}
else
{
printf(" ");
}
}
printf("\n");
}

return 0;
}

You might also like