BeginnersBook

  • Home
  • Java
    • Java OOPs
    • Java Collections
    • Java Examples
  • C
    • C Examples
  • C++
    • C++ Examples
  • DBMS
  • Computer Network
  • Python
    • Python Examples
  • More…
    • jQuery
    • Kotlin
    • WordPress
    • SEO
    • JSON
    • JSP
    • JSTL
    • Servlet
    • MongoDB
    • XML
    • Perl

C Program to Print Pyramid Star Pattern

Last Updated: July 21, 2022 by Chaitanya Singh | Filed Under: C Programs

In this tutorial, you will learn how write a C program to print the Pyramid star pattern.

This is how a Pyramid star pattern looks like:

Number of rows = 7
Output: 
          *
         * *
        * * *
       * * * *
      * * * * *
     * * * * * *   
    * * * * * * * 
The first row of the pyramid contains one star, second row two stars and so on

Program to print Pyramid Star Pattern

#include <stdio.h>
int main()
{
  int row, column, numberOfRows = 6;
  for (row=0; row<numberOfRows; row++)
  {
    for (column=numberOfRows-row; column>1; column--)
    {
      printf(" ");
    }
    for (column=0; column<=row; column++ )
    {
      printf("* ");
    }
    // Move the cursor to new line for next row
    printf("\n");
  }
  return 0;
}

Output:
C Program to Print Pyramid Star Pattern
Explanation of the program:
In this program, we are using loops to print pyramid star pattern. There are three loops in this program. The outer loop runs the same number of times the number of rows in pattern. In this example, number of rows are 6 so this loop runs 6 times, it has two inner loops.

The first inner for loop is to print the white spaces in each row. The second inner for loop is to print the stars in each row. This loop is pretty simple, it prints one star for first row, two stars for second row and so on.

Practice the same program in java language here.

Related C Examples:

  • C Program to print Left Triangle Star pattern
  • C Program to print Right Triangle Star pattern
  • C Program to add two numbers
  • C Program to print an integer entered by user
❮ C TutorialC Programs ❯

Top Related Articles:

  1. C Program to Print Right Triangle Star Pattern
  2. C Program to find Palindrome numbers in a given range
  3. C Program to print cube of a number upto an integer
  4. C Program to calculate Area and Circumference of Circle
  5. C Program to concatenate two strings without using strcat

About the Author

I have 15 years of experience in the IT industry, working with renowned multinational corporations. Additionally, I have dedicated over a decade to teaching, allowing me to refine my skills in delivering information in a simple and easily understandable manner.

– Chaitanya

Copyright © 2012 – 2025 BeginnersBook . Privacy Policy . Sitemap