C++ Program to Print Hollow Diamond Star Pattern

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

#include<iostream>
using namespace std;

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

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

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

    for(i = rows - 1; i > 0; i--)
    {
    	for(j = 1; j <= rows - i; j++)
		{
            cout << " ";
        }
        for(k = 1; k <= i * 2 - 1; k++)
        {
            if (k == 1 || k == i * 2 - 1)
            {
                cout << "*";
            }
            else
            {
                cout << " ";
            }
        }
        cout << "\n";
    }
	
 	return 0;
}
CPP Program to Print Hollow Diamond Star Pattern

This example prints the hollow diamond pattern of a given character using a while loop.

#include<iostream>
using namespace std;

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

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

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

    i = rows - 1;
    while( i > 0)
    {
    	j = 1;
    	while( j <= rows - i)
		{
            cout << " ";
            j++;
        }
        k = 1;
        while( k <= i * 2 - 1)
        {
            if (k == 1 || k == i * 2 - 1)
            {
                cout << ch;
            }
            else
            {
                cout << " ";
            }
            k++;
        }
        cout << "\n";
        i--;
    }
	
 	return 0;
}
Enter Hollow Diamond Star Pattern Row = 15
Enter Symbol for Hollow Diamond Pattern = $
              $
             $ $
            $   $
           $     $
          $       $
         $         $
        $           $
       $             $
      $               $
     $                 $
    $                   $
   $                     $
  $                       $
 $                         $
$                           $
 $                         $
  $                       $
   $                     $
    $                   $
     $                 $
      $               $
       $             $
        $           $
         $         $
          $       $
           $     $
            $   $
             $ $
              $