Home > Article > Backend Development > Write a program in C language to print a pyramid pattern
A pyramid is a polyhedron formed by connecting polygon bases and points called vertices. Each base and vertex form a triangle called a side. It is a cone with a polygonal base. A pyramid with an n-sided base has n 1 vertices, n 1 faces, and 2n sides. All pyramids are self-dual.
Accept the number of rows from the user to form pyramid shape Iterate the loop till the number of rows specified by the user: Display 1 star in the first row Increase the number of stars based on the number of rows.
/*Program to print Pyramid Pattern*/ #include<stdio.h> int main() { int r, s, rows=0; int t=0; clrscr(); printf("Enter number of rows to print the pyramid: "); scanf("%d", &rows); printf("</p><p>"); printf("The Pyramid Pattern for the number of rows are:"); printf("</p><p></p><p>"); for(r=1;r<=rows;++r,t=0) { for(s=1; s<=rows-r; ++s){ printf(" "); } while (t!=2*r-1) { printf("* "); ++t; } printf("</p><p>"); } getch(); return 0; }
The above is the detailed content of Write a program in C language to print a pyramid pattern. For more information, please follow other related articles on the PHP Chinese website!