C++ program to print Half Pyramid Pattern

 Half Pyramid Pattern

Here we will see programs to print half pyramid pattern using '*' and numbers.




(i)

Program:

#include <iostream>
using namespace std;

int  main()
{
    int n;
    cout<<"Enter number of rows: ";
    cin>>n;
    
for(int i=0;i<n;i++) //loop for changing line
{ for(int j=0;j<i+1;j++) //loop for printing * { cout<<"* "; } cout<<endl; } return 0; }

Output:

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

(ii)

Program:

#include <iostream>
using namespace std;

int  main()
{
    int n;
    cout<<"Enter number of rows: ";
    cin>>n;
    
    for(int i=0;i<n;i++) //loop for changing line
    {
        for(int j=0;j<i+1;j++) //loop for printing *
        {
            cout<<1<<" ";
        }
        cout<<endl;
    }
    
    return 0;
}

Output:

1
1 1
1 1 1
1 1 1 1
1 1 1 1 1

(iii)

Program:

#include <iostream>
using namespace std;

int  main()
{
    int n,count=0;
    cout<<"Enter number of rows: ";
    cin>>n;
    
    for(int i=0;i<n;i++) //loop for changing line
    {
        for(int j=0;j<i+1;j++) //loop for printing *
        {
	    count++;
            cout<<count<<" ";
        }
        cout<<endl;
    }
    
    return 0;
}

Output:

1
 3
4  5  6
7  8  9  10
11 12 13 14 15

C++ program to print Half Pyramid Pattern C++ program to print Half Pyramid Pattern Reviewed by Beast Coder on February 04, 2021 Rating: 5

No comments:

Powered by Blogger.