C Program To Print Hollow Star Pyramid
Here, we will print the hollow star pyramid pattern using a C program.
Input:
n = 5
Output:
*
* *
* *
* *
***********
C
#include <stdio.h>
int main()
{
int i, space, n = 5, j = 0;
for (i = 0; i < n - 1; i++) {
for (space = 1; space < n - i; space++) {
printf ( " " );
}
for (j = 0; j <= 2 * i; j++) {
if (j == 0 || j == 2 * i)
printf ( "*" );
else
printf ( " " );
}
printf ( "\n" );
}
for (i = 0; i < 2 * n - 1; i++) {
printf ( "*" );
}
return 0;
}
|
Output
*
* *
* *
* *
*********
Time Complexity: O(n^2) for given input n
Auxiliary Space: O(1)
Last Updated :
07 Aug, 2022
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...