Signup/Sign In
LAST UPDATED: JANUARY 10, 2022

Print Pyramid Star Pattern Program In C Language

learn C language tutorial

Logic To Print Pyramid Star Pattern Program:

  • Get the input from the user to print the Pyramid Star Pattern
  • To print the pyramid star pattern program an inner loop and outer loop is used
  • The outer loop is used to print the number of rows, the condition will run from 0 to i, r-i.
  • The inner loop is used to print the stars, the condition will be 2*j+1.

C Language Program To Print The Pyramid Star Pattern Program:

 #include <stdio.h> int main() { int i, space, rows, k = 0; printf("Enter The Number Of Rows To Print Pyramid Star Pattern: "); scanf("%d", &rows); for (i = 1; i <= rows; ++i, k = 0) { for (space = 1; space <= rows - i; ++space) { printf(" "); } while (k != 2 * i - 1) { printf("* "); ++k; } printf("\n"); } return 0; }

Output:

Pyramid



About the author:
I like writing content about C/C++, DBMS, Java, Docker, general How-tos, Linux, PHP, Java, Go lang, Cloud, and Web development. I have 10 years of diverse experience in software development. Founder @ Studytonight