- 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 Different pattern Bash in C++
This article is intended to print a half-pyramid pattern bash using the C++ programming language. In the view of the stipulated pattern to be printed, the following algorithm is being orchestrated to achieve our goal as;
Algorithm
Step-1 Set the length of the Bash (Height) Step-2 Outer loop to handle the number of rows Step-3 Inner loop to handle columns Step-4 Print the pattern with the character (@) Step-5 Set the pointer to a new line after each row (outside the inner loop) Step-6 Repeat the loop till the Bash Height
Example
So, the following C++ source code is ultimately carved out by complying the aforesaid algorithm as follows;
#include <iostream> using namespace std; void PrintBash(int n){ // outer loop to handle number of rows for (int i=0; i<n; i++){ // inner loop to handle number of columns for(int j=0; j<=i; j++ ){ // printing character cout << "@ "; } // ending line after each row cout << endl; } } int main(){ int Len = 6; PrintBash(Len); return 0; }
Output
After compilation of the above code, the half-pyramid will be printed looks like as.
@ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @
Advertisements