
- C Programming Tutorial
- C - Home
- C - Overview
- C - Environment Setup
- C - Program Structure
- C - Basic Syntax
- C - Data Types
- C - Variables
- C - Constants
- C - Storage Classes
- C - Operators
- C - Decision Making
- C - Loops
- C - Functions
- C - Scope Rules
- C - Arrays
- C - Pointers
- C - Strings
- C - Structures
- C - Unions
- C - Bit Fields
- C - Typedef
- C - Input & Output
- C - File I/O
- C - Preprocessors
- C - Header Files
- C - Type Casting
- C - Error Handling
- C - Recursion
- C - Variable Arguments
- C - Memory Management
- C - Command Line Arguments
- C Programming useful Resources
- C - Questions & Answers
- C - Quick Guide
- C - Useful Resources
- C - Discussion
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("
"); printf("The Pyramid Pattern for the number of rows are:"); printf("
"); for(r=1;r<=rows;++r,t=0) { for(s=1; s<=rows-r; ++s){ printf(" "); } while (t!=2*r-1) { printf("* "); ++t; } printf("
"); } getch(); return 0; }
Output
- Related Articles
- C Program to print hollow pyramid and diamond pattern
- Program to print hollow pyramid and diamond pattern in C++
- Program to print an inverse pyramid character pattern in C++
- Java Program to Print Pyramid Star Pattern
- Swift program to Print Pyramid Star Pattern
- Swift Program to Print Numeric Pyramid Pattern
- Golang Program to Print Pyramid Star Pattern
- Print Pyramid Star Pattern in Java Program
- PHP program to print a pattern of pyramid
- Swift program to Print Reverse Pyramid Star Pattern
- Swift Program to Print Reverse Numeric Pyramid Pattern
- Golang Program to Print Reverse Pyramid Star Pattern
- Swift Program to Print Reverse Pyramid Alphabetic Pattern
- Java Program to Create Pyramid and Pattern
- Golang Program To Create Pyramid And Pattern

Advertisements