**Part-3: Pyramid pattern problems using **numbers

In previous part, we learnt about making of patterns using stars or character. In this part, we will learn to make these patterns with different sequence of numbers.

### Topics Covered

- print half pyramid pattern using numbers
- print an inverted half pyramid using numbers
- print half pyramid pattern using numbers (Type-2).
- print an inverted half pyramid using numbers(Type-2).

**Print half pyramid pattern using numbers**

```
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
```

Look at the pattern, as we see there are numbers arranged in the pyramid in a certain pattern and just observe the pattern. We print one number in row 1, two numbers in row 2, and so on and when we see column wise we print the number which is the column’s number. So what we have to do is just do this with code

**CODE:**

```
#include<iostream>
using namespace std;
int main()
{
int n;
cout<<"Enter the height of pyramid :"<<endl;
cin>>n;
for(int i=1; i<=n; i++)
{
for(int j=1; j<=i; j++)
{
cout<< j <<" ";
}
cout<<endl;
}
return 0;
}
```

**OUTPUT:**

**Print an inverted half pyramid using numbers**

```
1 2 3 4 5
1 2 3 4
1 2 3
1 2
1
```

Look at this pattern, you will realize that this pattern is similar to the previous one with a little change and the change is in the row pattern, the column concept is the same. The change in the row concept is here we print the numbers in the amount, height of pyramid minus the row number.

**CODE:**

```
#include<iostream>
using namespace std;
int main()
{
int n;
cout<<"Enter the height of pyramid :"<<endl;
cin>>n;
for(int i=n; i>=1; i--)
{
for(int j=1; j<=i; j++)
{
cout<< j <<" ";
}
cout<<endl;
}
return 0;
}
```

**OUTPUT:**

## Print half pyramid pattern using numbers (Type-2).

```
1
2 2
3 3 3
4 4 4 4
5 5 5 5 5
```

When we look at the pattern of this pyramid you realize that it’s concept is same as the 1st pattern question . Here we have to print the numbers according to their column’s number i.e. print 1 in 1st row, 2 in 2nd row and so on. so let’s try this with code

**CODE:**

```
#include<iostream>
using namespace std;
int main()
{
int n;
cout<<"Enter the height of pyramid :"<<endl;
cin>>n;
for(int i=1; i<=n; i++)
{
for(int j=1; j<=i; j++)
{
cout<< i <<" ";
}
cout<<endl;
}
return 0;
}
```

**OUTPUT:**

**Print an inverted half pyramid using numbers(Type-2)**

```
1 1 1 1 1
2 2 2 2
3 3 3
4 4
5
```

Here in this pattern we see that numbers are printing in the row in the amount of height of the pyramid minus the row number. So, by using this concept let’s try to code this pattern

**CODE:**

```
#include<iostream>
using namespace std;
int main()
{
int n;
cout<<"Enter the height of pyramid :"<<endl;
cin>>n;
for(int i=1; i<=n; i++)
{
for(int j=1; j<=n-i+1; j++)
{
cout<< i <<" ";
}
cout<<endl;
}
return 0;
}
```

**OUTPUT:**

As we discussed some patterns of pyramids with the help of numbers but to make a better understanding of these topics you have to do more practice. Try different patterns with a different sequence of numbers and make your topic strong.

*In Part-4, we will discuss some famous mathematical triangles that are generally asked.*