# Diamond Pattern in C++

Diamond pattern is nothing but to print in diamond shape. We can print stars, numbers, alphabets in diamond shape. If we enter number of rows then it will print the diamond shape in that rows. We have three coding to print in diamond pattern in this article.

• Print Diamond Pattern of Stars
• Print Diamond pattern of Numbers
• Diamond Pattern of Alphabet Characters

## Program Code for Draw Diamond Pattern of Stars in C++

#include<iostream>
using namespace std;
int main()
{
int i, j, rowNum, space;
cout<<"Enter the Number of Rows: ";
cin>>rowNum;
space = rowNum-1;
for(i=1; i<=rowNum; i++)
{
for(j=1; j<=space; j++)
cout<<" ";
space--;
for(j=1; j<=(2*i-1); j++)
cout<<"*";
cout<<endl;
}
space = 1;
for(i=1; i<=(rowNum-1); i++)
{
for(j=1; j<=space; j++)
cout<<" ";
space++;
for(j=1; j<=(2*(rowNum-i)-1); j++)
cout<<"*";
cout<<endl;
}
cout<<endl;
return 0;
}
Read Also : Factorial Program in C++

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

## Diamond Pattern of Numbers in C++

If the user enter number of rows then it will print numbers in diamond shape. If we enter 5 rows then the center row has 5 numbers from 1 to 5. If we enter 10 rows then the center row has 10 numbers from 1 to 10.

#include<iostream>
using namespace std;
int main()
{
int i, j, rowNum, space, num=1;
cout<<"Enter the Number of Rows: ";
cin>>rowNum;
space = rowNum-1;
for(i=1; i<=rowNum; i++)
{
for(j=1; j<=space; j++)
cout<<" ";
space--;
for(j=1; j<=(2*i-1); j++)
{
cout<<num;
num++;
}
cout<<endl;
num = 1;
}
space = 1;
for(i=1; i<=(rowNum-1); i++)
{
for(j=1; j<=space; j++)
cout<<" ";
space++;
for(j=1; j<=(2*(rowNum-i)-1); j++)
{
cout<<num;
num++;
}
cout<<endl;
num = 1;
}
cout<<endl;
return 0;
}

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

## Diamond Pattern of Alphabets in C++

We can print diamond shape of letters in C++.

#include<iostream>
using namespace std;
int main()
{
int i, j, rowNum, space;
char ch='A';
cout<<"Enter the Number of Rows: ";
cin>>rowNum;
space = rowNum-1;
for(i=1; i<=rowNum; i++)
{
for(j=1; j<=space; j++)
cout<<" ";
space--;
for(j=1; j<=(2*i-1); j++)
{
cout<<ch;
ch++;
}
cout<<endl;
ch = 'A';
}
space = 1;
for(i=1; i<=(rowNum-1); i++)
{
for(j=1; j<=space; j++)
cout<<" ";
space++;
for(j=1; j<=(2*(rowNum-i)-1); j++)
{
cout<<ch;
ch++;
}
cout<<endl;
ch = 'A';
}
cout<<endl;
return 0;
}

A
A  B C
A B C D E
A B C
A