Print half and full start pyramid pattern in C

In this article, we are going to learn about a program to print a half Pyramid and full Pyramid pattern in C language. First, we are going to print the half Pyramid and then in the next program, we will print the full Pyramid.

  1. How to print half Pyramid using * in C language.
  2. How to print full Pyramid using * in C language.

How to print half Pyramid * in C language


In this example, we are going to print the half * pyramid using the C language. We will make use of the for loops.

C Program to print half Pyramid pattern


#include<stdio.h>
int main()
{
  int num, row, col;

  printf("Please enter the number of rows: ");
  scanf("%d",&num);

  for(row = 1; row <= num; row++)
  {
    for(int s=1;s<=num-row;s++) 
        printf(" ");
    for(col = 1;col <= row; col++) 
        printf("*");

    printf("\n");
  }

  return 0;
}

output

Please enter the number of rows: 5
    *
   **
  ***
 ****
*****

How to print full Pyramid using * in C language.


In this example, we are going to print the full * pyramid using C language. We will make use of the for loops.

Desired Output for Size 5:

    *
   **
  ***
 ****
*****

C Program to print pyramid of stars

#include<stdio.h>
int main()
{ int num, row, col;
printf("Enter number of rows: ");
scanf("%d",&num);

for(row = 1; row <= num; row++)
{
  for(int s=1;s<=num-row;s++) 
     printf(" ");
  for(col=1;col<=row;col++) 
     printf("* ");

  printf("\n");
}

return 0;
}

Output

Enter number of rows: 5
    * 
   * * 
  * * * 
 * * * * 
* * * * *