- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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.
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
Advertisements