C++ Program to Print Hollow Diamond inside a Square Star Pattern

Write a C++ program to print the hollow diamond star pattern inside a square pattern using for loop.

#include<iostream>
using namespace std;

int main()
{
	int i, j, k, l, rows;
     
    cout << "Enter Hollow Diamond Star Pattern Row = ";
    cin >> rows;

    cout << "Hollow Diamond Star Pattern\n"; 

    for(i = 1; i <= rows; i++)
    {
    	for(j = i; j <= rows; j++)
		{
            cout << "*";
        }
        for(k = 1; k <= i * 2 - 2; k++)
        {
            cout << " ";
        }
        for(l = i; l <= rows; l++)
        {
            cout << "*";
        }
        cout << "\n";
    }	

    for(i = 1; i <= rows; i++)
    {
    	for(j = 1; j <= i; j++)
		{
            cout << "*";
        }
        for (k = 2 * i - 2 ; k < 2 * rows - 2; k++ ) 
        {
            cout << " ";
        }
        for(l = 1; l <= i; l++)
        {
            cout << "*";
        }
        cout << "\n";
    }
	
 	return 0;
}
C++ Program to Print Hollow Diamond inside a Square Star Pattern

This C++ example prints the hollow diamond shape of a given character inside a square pattern.

#include<iostream>
using namespace std;

int main()
{
	int i = 1, j, k, l, rows;
    char ch;
     
    cout << "Enter Row = ";
    cin >> rows;

    cout << "Enter Symbol for Hollow Diamond Pattern = ";
    cin >> ch;


    while(i <= rows)
    {
        j = i; 
    	while(j <= rows)
		{
            cout << ch;
            j++;
        }
        k = 1;
        while( k <= i * 2 - 2)
        {
            cout << " ";
            k++;
        }
        l = i;
        while( l <= rows)
        {
            cout << ch;
            l++;
        }
        cout << "\n";
        i++;
    }	

    i = 1;
    while( i <= rows)
    {
        j = 1; 
    	while(j <= i)
		{
            cout << ch;
            j++;
        }
        k = 2 * i - 2 ;
        while ( k < 2 * rows - 2) 
        {
            cout << " ";
            k++;
        }
        l = 1;
        while( l <= i)
        {
            cout << ch;
            l++;
        }
        cout << "\n";
        i++;
    }
 	return 0;
}
Enter Row = 12
Enter Symbol for Hollow Diamond Pattern = @

@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@  @@@@@@@@@@@
@@@@@@@@@@    @@@@@@@@@@
@@@@@@@@@      @@@@@@@@@
@@@@@@@@        @@@@@@@@
@@@@@@@          @@@@@@@
@@@@@@            @@@@@@
@@@@@              @@@@@
@@@@                @@@@
@@@                  @@@
@@                    @@
@                      @
@                      @
@@                    @@
@@@                  @@@
@@@@                @@@@
@@@@@              @@@@@
@@@@@@            @@@@@@
@@@@@@@          @@@@@@@
@@@@@@@@        @@@@@@@@
@@@@@@@@@      @@@@@@@@@
@@@@@@@@@@    @@@@@@@@@@
@@@@@@@@@@@  @@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@

About Suresh

Suresh is the founder of TutorialGateway and a freelance software developer. He specialized in Designing and Developing Windows and Web applications. The experience he gained in Programming and BI integration, and reporting tools translates into this blog. You can find him on Facebook or Twitter.