
- C++ Basics
- C++ Home
- C++ Overview
- C++ Environment Setup
- C++ Basic Syntax
- C++ Comments
- C++ Data Types
- C++ Variable Types
- C++ Variable Scope
- C++ Constants/Literals
- C++ Modifier Types
- C++ Storage Classes
- C++ Operators
- C++ Loop Types
- C++ Decision Making
- C++ Functions
- C++ Numbers
- C++ Arrays
- C++ Strings
- C++ Pointers
- C++ References
- C++ Date & Time
- C++ Basic Input/Output
- C++ Data Structures
- C++ Object Oriented
- C++ Classes & Objects
- C++ Inheritance
- C++ Overloading
- C++ Polymorphism
- C++ Abstraction
- C++ Encapsulation
- C++ Interfaces
Printing Pyramid in C++
This article yields a “pyramid-like structure” as an output using the C++ programming code. In which the pyramid height and space are being determined by traversing double for loop constructs as following;
Example
#include <iostream> using namespace std; int main() { int space, rows=6; for(int i = 1, k = 0; i <= rows; ++i, k = 0){ for(space = 1; space <= rows-i; ++space){ cout <<" "; } while(k != 2*i-1){ cout << "* "; ++k; } cout << endl; } return 0; }
Output
After compilation of the above code, the pyramid will be printed looks like as.
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
- Related Articles
- Printing Pyramid using Recursion in C++
- Programs for printing pyramid patterns in Python
- Java Programs for printing Pyramid Patterns. (of numbers)
- Difference Between Transfer Printing and Digital Printing
- What is pyramid?
- Define prism and pyramid
- Printing Heart Pattern in C
- Printing Interesting pattern in C++
- Multi-Line printing in Python
- Printing Triangle Pattern in Java
- Importance of Printing in Fabrics
- Methods of Printing
- Is a book printing press different from a magazine printing press?
- Program for volume of Pyramid in C++
- Print pyramid of tutorialspoint in PL/SQL

Advertisements