In this tutorial, we will discuss the Cpp program to pyramid number pattern
In this topic, we will learn how to create number pattern in C++ language using for loop and while loop
pyramid number pattern programs in C++language
Pattern 1
Number Pyramid pattern 1
Pyramid triangle number pattern program 1
#include
#include
using namespace std;
int main()
{
int i,j,k,rows;
cout<<"Enter the rows: ";
cin>>rows;//get input from user
for(i=1; i<=rows; i++){
for(j=1; j<=rows; j++){
cout <<" ";//print space
}
for(k=1; k<=i; k++){
cout <
When the above code is compiled and executed, it produces the following results
Enter the rows: 9
1
2 2
3 3 3
4 4 4 4
5 5 5 5 5
Pattern 2
Number Pyramid pattern 2
Pyramid triangle number pattern program 2
#include
#include
using namespace std;
int main()
{
int rows,i,j,k,l=1;
cout<<"Enter the number of rows :";
cin>>rows;//get user input from user
cout<<"Here your pyramid pattern\n";
for(i=1; i<=rows; i++){
for(j=1; j<=rows-i; j++){//iterates for print space
cout<<" ";//print space
}
for(k=1; k<=i; k++){
cout<
When the above code is compiled and executed, it produces the following results
Enter the number of rows :7
Here your pyramid pattern
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
1 2 3 4 5 6
1 2 3 4 5 6 7
Pattern 3
Number Pyramid pattern 3
Pyramid triangle number pattern program 3
#include
#include
using namespace std;
int main()
{
int rows,i,j,k,l=1;
cout<<"Enter the number of rows :";
cin>>rows;
cout<<"Here your pyramid pattern\n";
for(i=1; i<=rows; i++){
for(j=1; j<=rows-i; j++){//iterates for space
cout<<" ";//print initial space for pyramid shape
}
for(k=1; k<=i; k++,l++){
cout<
When the above code is compiled and executed, it produces the following results
Enter the number of rows: 4
Here your pyramid pattern
1
2 3
4 5 6
7 8 9 10
Pattern 4
Number Pyramid pattern 4
Pyramid triangle number pattern program 4
Pascal triangle pyramid pattern
#include
#include
using namespace std;
int main()
{
int rows,i,j,space_count,count1=1;
cout<<"Enter the number of rows: \n";
cin>>rows;
for(i=0; i<=rows; i++){//outer for loop - parent
for(space_count=1; space_count<=rows-i; space_count++){
cout<<" ";//print space-inner for loop
}
for(j=0; j<=i; j++){
if(j==0 || i==0)
count1=1;
else
count1=count1*(i-j+1)/j;
cout<
When the above code is compiled and executed, it produces the following results
#include
#include
using namespace std;
int main()
{
int rows,i,j=0,num=0,count1=0,spaceCount;
cout<<"Enter the number of rows: \n";
cin>>rows;
for(i=1; i<=rows; i++){//outer for loop - parent
for(spaceCount=1; spaceCount<=rows-i; spaceCount++){
cout<<" ";//print space-inner for loop
count1++;
}
while(j!=2*i-1)
{
if(count1<=rows-1){
cout<
When the above code is compiled and executed, it produces the following results
Enter the number of rows:
4
1
2 3 4
3 4 5 6 7
4 5 6 7 8 9 10
Pattern 6
Number Pyramid pattern 6
Pyramid triangle number pattern program 6
#include
#include
using namespace std;
int main()
{
int rows,i,j=0,num=0,count1=0,spaceCount;
cout<<"Enter the number of rows: \n";
cin>>rows;
for(i=1; i<=rows; i++){//outer for loop - parent
for(spaceCount=1; spaceCount<=rows-i; spaceCount++){
cout<<" ";//print space-inner for loop
count1++;
}
while(j!=2*i-1)
{
if(count1<=rows-1){
cout<
When the above code is compiled and executed, it produces the following results
Enter the number of rows:
6
1
232
34543
4567654
567898765
67891011109876
Pattern 7
Number Pyramid pattern 7
Pyramid triangle number pattern program 7
#include
#include
using namespace std;
int main()
{
int rows,i,j;
cout<<"Enter the number of rows: \n";
cin>>rows;
for(i=1; i<=rows; i++){//outer for loop - parent
for(j=1; j<=rows-i; j++){
cout<<" ";//print space-inner for loop
}
for(j=1; j
When the above code is compiled and executed, it produces the following results
Enter the number of rows:
8
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
1 2 3 4 5 6
1 2 3 4 5 6 7
No Comments
ss April 2, 2021 at 1:30 pm
#include
using namespace std;
int main()
cout<<" ";
{
int i,j,k,row,c,l;
cin>>row;
for(i=1;i<=row;i++)
{
for(j=i;j
for(c=i,k=1;k<=i;k++)
{
cout<=1;l–)
{
cout< c–;
}
cout< }
return 0;
}