C Program to print half and full start Pyramid

Python

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

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

1. How to print inverted half start Pyramid in C


In this c program example, we are printing an inverted start pyramid with the help of for loop.

Desired Output for Size 5:

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

C program to print inverted half start Pyramid

#include<stdio.h>
int main()
{

  int num;

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

  for(int i=num;i>=1;i--)
  {

    for(int j = i; j >= 1; j--)
    {
       printf("* ");
    }

    printf("\n");
  }

  return 0;
}

Output

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

2. How to print full inverted start Pyramid in C


C program to print inverted half start Pyramid

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

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

  for(row = num; row >= 1; 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
* * * * * 
 * * * * 
  * * * 
   * * 
    *