- 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
Program to print an inverse pyramid character pattern in C++
In this tutorial, we will be discussing a program to print an inverse pyramid character pattern.
For this we will be provided with the number of rows containing in the inverted pyramid triangle. Our task is to print the alphabets in the given number of rows to develop the shape of an inverse pyramid.
Example
#include <bits/stdc++.h> using namespace std; //printing the inverse pyramid pattern void inv_pyramid(int n){ int i, j, num, gap; for (i = n; i >= 1; i--) { for (gap = n - 1; gap >= i; gap--) { cout<<" "; cout<<" "; } num = 'A'; for (j = 1; j <= i; j++) { cout << (char) num++ <<" "; } for (j = i - 1; j >= 0; j--) { cout << (char) --num <<" "; } cout<<"\n"; } } int main(){ int n = 5; inv_pyramid(n); return 0; }
Output
A B C D E E D C B A A B C D D C B A A B C C B A A B B A A A
Advertisements