C++ Program To Print Patterns

Spread the love


pattern structures are common to test someone’s ability in logic and programming.this is the only thing where you have to implement your programming skills.these patterns structures are mainly used to checking programmers ability to code.for designing these patterns you must know to programming looping statements like for loop, while loop, do while loop, break and continue statements.you can use any programming language for that but here I used C++ for designing patterns.

C++ Program To Print Patterns

C++ Program To Print Patterns

Before writing any program for designing patterns if you trace it on paper then it will easy to understand the placement of starts(*).draw some needed amount of columns and rows on paper and give them number count so you can easily traverse looping statements according to your needs.i have shown it in above image please refer that.

 

#include

using namespace std;

int main() {
for(int i=5;i>=1;i--){

for(int j=i;j>=1;j--){

cout<<"*";
}
cout << endl;
}

}

Program Description:

in above program i took two for loops for drawing this patterns.first for loop for rows and coloumns and secound for loops for printing starts(*).endl is used for braking current line and focous goes to the new line.

 

Output:

2)

#include

using namespace std;

int main() {
for(int i=1;i<=5;i++){

for(int j=1;j<=i;j++){

cout<<"*";
}
cout << endl;
}

}

Program Description:if you want to change patterns structure of above program then just change conditions in for loop and increment loop counter.

Output:



c++ program to print patterns

c++ program to print patterns

#include

using namespace std;

int main() {
for(int i=1;i<=5;i++){

for(int j=1;j<=i;j++){

cout<<" ";
}
for(int k=1;k<=5-i;k++){

cout<<"#";
}

cout << endl;
}

}

Program Description:ithis example works same like previous one but I wrote second for loop for managing space before pattern structure

Output:

c++ program to print patterns 3

c++ program to print patterns 3

3)

#include

using namespace std;

int main() {
for(int i=1;i<=5;i++){

for(int j=1;j<=i;j++){

cout<<" "; } for(int k=5-i;k>=0;k--){

cout<<"#"; } for(int s=5-i;s>=1;s--){

cout<<"#";
}

cout << endl;
}

}
c++ program to print patterns 4

c++ program to print patterns 4

4)

#include

using namespace std;

int main() {
for(int i=1;i<=5;i++){

for(int j=1;j<=i;j++){

cout<<" "; } for(int k=5-i;k>=0;k--){

cout<<"*"; } for(int k=5-i;k>=1;k--){

cout<<"*";
}

cout << endl; } for(int i=5;i>=1;i--){

for(int j=1;j<=i;j++){

cout<<" "; } for(int k=5-i;k>=0;k--){

cout<<"*"; } for(int k=5-i;k>=1;k--){

cout<<"*";
}

cout << endl;
}

}
c++ program to print patterns 5

c++ program to print patterns 5

 

Leave a Reply

Your email address will not be published. Required fields are marked *

Geekbaba.org - Hot News ,Tutorials,Tips & Tricks,Entertainment,Sports,Business World. © 2017