

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Program to print pyramid pattern in C
Program Description
A pyramid is a polyhedron formed by connecting a polygonal base and a point, called the apex. Each base edge and apex form a triangle, called a lateral face. It is a conic solid with polygonal base. A pyramid with an n-sided base has n + 1 vertices, n + 1 faces, and 2n edges. All pyramids are self-dual.
Algorithm
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.
Example
/*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("\n"); printf("The Pyramid Pattern for the number of rows are:"); printf("\n\n"); for(r=1;r<=rows;++r,t=0) { for(s=1; s<=rows-r; ++s){ printf(" "); } while (t!=2*r-1) { printf("* "); ++t; } printf("\n"); } getch(); return 0; }
Output
- Related Questions & Answers
- Java Program to Print Pyramid Star Pattern
- C Program to print hollow pyramid and diamond pattern
- Print Pyramid Star Pattern in Java Program
- Program to print hollow pyramid and diamond pattern in C++
- Program to print an inverse pyramid character pattern in C++
- PHP program to print a pattern of pyramid
- Java Program to Create Pyramid and Pattern
- C++ Programs To Create Pyramid and Pattern
- Program to print Interesting pattern in C++
- Program to print Kite Pattern in C++
- Program to print number pattern in C
- Program to print Diamond Pattern in C
- Program to print numeric pattern in C
- Program to print a rectangle pattern in C++
- Program to print Inverse Diamond pattern on C++
Advertisements