Diamond number pattern in C++ language
- Home
- Diamond pattern
- Diamond number pattern in C++ language
- On
- By
- 0 Comment
- Categories: Diamond pattern, Number pattern
Diamond number pattern in C++ language
Diamond number pattern in C++ language
In this tutorial, we will discuss a simple concept of the Diamond number pattern in C++ language
In this post, we will learn how to create diamond number pattern
we can use for loop, while loop or do while loop to display different types of diamond patterns in C++ language

Here, we will use for loop and nested for loop to print different type of number patterns
Program 1
Diamond number pattern in C++ language
Diamond pattern 1
#include <iostream>
using namespace std;
int main()
{
int rows;
cout<<"Enter the number of rows: ";
cin>>rows;
int row=1,i,j,k;
for(i=rows/2; i>0; i--){ //print upper part
for(j=1; j<=i; j++){
cout<<" ";
}
for(j=1; j<=row; j++){
cout<<row;
cout<<" ";
}
cout<<"\n";//move to next line
row++;
}
for(i=0; i<=rows/2; i++){
for(j=1; j<=i; j++){
cout<<" ";
}
for(j=row; j>=1; j--){ //print lower part
cout<<row;
cout<<" ";
}
cout<<"\n";//move to next line
row--;
}
return 0;
}
When the above code is executed, it produces the following result
Enter the number of rows: 8
1
2 2
3 3 3
4 4 4 4
5 5 5 5 5
4 4 4 4
3 3 3
2 2
1
Program 2
Diamond pattern 2
#include <iostream>
#include <conio.h>
using namespace std;
int main()
{
int i,j,k,l,rows;
cout<<"|Enter the number of rows: ";
cin>>rows;
for(i=1; i<=rows; i++){ //print upper part
for(j=1; j<=rows-i; j++){
cout<<" ";//print initial space for upper part
}
for(k=i; k>=1; k--){
cout<<k;
}
for(l=2; l<=i; l++){
cout<<l;
}
cout<<"\n";//move to next line
}
for(i=rows-1; i>=1; i--){ //print lower part
for(j=0; j<=rows-1-i; j++){
cout<<" ";//print initial space for lower part
}
for(k=i; k>=1; k--){
cout<<k;
}
for(l=2; l<=i; l++){
cout<<l;
}
cout<<"\n";//move to next line
}
getch();
return 0;
}
When the above code is executed, it produces the following result
Enter the number of rows: 6
1
212
32123
4321234
543212345
65432123456
543212345
4321234
32123
212
1
Program 3
Diamond pattern 3
#include <iostream>
using namespace std;
int main()
{
int rows;
cout<<"Enter the number of rows: ";
cin>>rows;
int row=1,i,j,k;
for(i=1; i<=rows; i++){ //print upper part
for(j=1; j<=rows-i; j++){
cout<<" ";//print space
}
for(k=1; k<=i; k++){
cout<<k;
cout<<" ";
}
cout<<"\n";//move to next line
}
for(i=1; i<=rows-1; i++){ //print lower part
for(j=1; j<=i; j++){
cout<<" ";
}
for(k=1; k<=rows-i; k++){
cout<<k;
cout<<" ";
}
cout<<"\n";//move to next line
}
}
When the above code is executed, it produces the following result
Enter the number of rows: 6
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
1 2 3 4
1 2 3
1 2
1
Similar post
Diamond number pattern in Java language
Diamond patterns in C language
integrated pyramid star pattern in C
integrated pyramid star pattern in Java
C++ code to Double pyramid star pattern
Java code to Double pyramid star pattern
Java program to Display diamond number pattern using while loop
C++ code to Display diamond number pattern using while loop
Floyd’s triangle number pattern using for loop in C
Floyd’s triangle pattern using nested for loop in Java
Floyd’s triangle pattern using nested while loop in Java
Hollow pyramid triangle pattern in C++ language
Rhombus pattern in Java using for loop
Rhombus pattern in C using while loop
Rhombus pattern in C++ using do-while loop
Display Pyramid star pattern in C
Display Pyramid star pattern in Java
Suggested for you
Nested for loop in Java language
Nested for loop in C++ language
Nested for loop in Python language
If statements in Java language
Nested if statements in Java language