You can break this into 2 parts, first inverted triangle and then left hand side triangle, so C Code for it will look like below
#include <stdio.h>
int main()
{
//declare variables to use
int i, j, rows;
//now loop for each row
for(i=1; i<=5; ++i)
{
//this loop will print * until value of outer loop variable(i) is greater than
//inner loop vairable(j)
for(j=5; j>=i; j--)
{
printf("*");
}
//as soon as inner loop(j) value becomes greater than outer loop printing * ends
// & it prints new line using \n
printf("\n");
}
//now loop for each row
for(i=2; i<=5; ++i)
{
//this loop will print * until value of outer loop variable(i) is greater than
//inner loop vairable(j)
for(j=1; j<=i; ++j)
{
printf("*");
}
//as soon as inner loop(j) value becomes greater than outer loop printing * ends
// & it prints new line using \n
printf("\n");
}
return 0;
}
Output:
*****
****
***
**
*
**
***
****
*****
Sample https://onlinegdb.com/ZuFVWV4v0
For more Star program in C (Pyramid pattern program examples) check link.
Subscribe to our weekly Newsletter & Keep getting latest article/questions in your inbox weekly