* pattern program in c++

You all know about programming language. There are many language available for programming but most commen use programming language is C, C++, Java, Right. So, Here we dicuss about pettern program. pettern is important in programming because it’s help to develop our logic. So, we’ll show 4 pattern in C++ or CPP language with output. So, If any doubt regarding this pattern please comment below.

Example 1


//alphaprogrammer.in

#include<iostream>
using namespace std;
int main()
{
    int i,j,n;
    cin>>n;
    for(i=1;i<=n;i++)
    {
        for(j=1;j<=i;j++)
        {
            cout<<"* ";
        }
        cout<<"\n";
    }
    return 0;
}


Output :-

    *
    * *
    * * *
    * * * *
    * * * * *

This pattern is most populer pattern. you can try with your own method and if any problem you faced then you can use the logic of this code.

Example 2

//alphaprogrammer.in

#include<iostream>
using namespace std;
int main()
{
    int i,j,n;
    cin>>n;
    for(i=1;i<=n;i++)
    {
        for(j=n;j>=i;j--)
        {
            cout<<"* ";
        }
        cout<<"\n";
    }
    return 0;
}

Output :-

    * * * *
    * * *
    * *
    *

Example 3

//alphaprogrammer.in

#include<iostream>
using namespace std;
int main()
{
    int i,j,k,n;
    cin>>n;
    for(i=1;i<=n;i++)
    {
        for(k=n;k>=i;k--)
        {
            cout<<" ";
        }
        for(j=1;j<=i;j++)
        {
            cout<<"* ";
        }
        cout<<"\n";
    }
    return 0;
}


Output :-

        *
       * *
      * * *
     * * * *

Example 4

//alphaprogrammer.in


#include<iostream>
using namespace std;
int main()
{
    int i,j,k,n;
    cin>>n;
    for(i=1;i<=n;i++)
    {
        for(k=1;k<=i;k++)
        {
            cout<<" ";
        }
        for(j=n;j>=i;j--)
        {
            cout<<"* ";
        }
        cout<<"\n";
    }
    return 0;
}


Output :-

     * * * *
      * * *
       * *
        *

I hope you guys this will help for you. If you interested in more pattern with this video.

If you interested in technology video then subscribe our channel alphaprogrammer.

Thank you 🙂

Leave a Comment

Your email address will not be published.