C++ program to print pattern Example 2

C++ program to print pattern Example 2

In this chapter of C++ program tutorial our task is:

  • write a program in c++ to print star pattern


* *

* * *

* * * *

C++  pattern printing program Example 2

Given below is a c++ program to print star patterns as shown above:

//program author : Sayantan Bose
using namespace std;
//This the function to print the given pattern
void pattern(int noOfLines)
    int i,j;
    for(i=1;i<=noOfLines;i++){       //keep a track of the rows
        for(j=1;j<=i;j++){   //keep a track of the columns
            cout<<"* ";
//This is the main function
int main()
    int n;
    cout<<"Enter the number of lines you want enter"<<endl;
    cout<<"The following is the required pattern"<<endl;
    return 0;


Enter the number of lines you want enter

The following is the required pattern
* *
* * *
* * * *
EXPLANATION for star pattern programs:
In the above c++ star pattern programs:
  • From the main function the user is taking the required number of lines that needs to be printed
  • Then a function "pattern" is called to print the required pattern
  • There are two variables name "i" and "j"
  • "i" keep a track of number of rows
  • "j" keep a track of number of columns
  • In this program the "j" loop is running till the number of rows i.e "i"

This is also an example of nested loop

You can see the above code execution and output in codeblocks IDE:  

C++ program to print pattern Example 2


CPP Programs

Would you like to see your article here on tutorialsinhand. Join Write4Us program by

About the Author
Sayantan Bose
- šŸ”­ Iā€™m currently working on DS Algo skills - šŸŒ± Iā€™m currently learning web develeopement - šŸ‘Æ Iā€™m looking to collaborate with Oppia - šŸ“« Reach me at - šŸ˜„ Pronouns: his/him
Page Views :    Published Date : Oct 07,2020  
Please Share this page

Related Articles

Like every other website we use cookies. By using our site you acknowledge that you have read and understand our Cookie Policy, Privacy Policy, and our Terms of Service. Learn more Got it!