C++ Program to Print Mirrored Half Diamond Star Pattern

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

#include<iostream>
using namespace std;

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

    cout << "Mirrored Half Diamond Star Pattern\n"; 

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

    for(i = rows - 1; i > 0; i--)
    {
    	for(j = 1; j <= rows - i; j++)
		{
            cout << " ";
        }
        for(k = 1; k <= i; k++)
		{
            cout << "*";
        }
        cout << "\n";
    }	
 	return 0;
}
C++ Program to Print Mirrored Half Diamond Star Pattern

This C++ example prints the mirrored half 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 Mirrored Half Diamond Star Pattern Row = ";
    cin >> rows;

    cout << "Enter Symbol Mirrored Half Diamond Pattern = ";
    cin >> ch;

    cout << "Mirrored Half Diamond Star Pattern\n"; 

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

    i = rows - 1;
    while( i > 0)
    {
    	j = 1;
    	while( j <= rows - i)
		{
            cout << " ";
            j++;
        }
        k = 1;
        while( k <= i)
		{
            cout << ch;
            k++;
        }
        cout << "\n";
        i--;
    }	
 	return 0;
}
Enter Mirrored Half Diamond Star Pattern Row = 9
Enter Symbol Mirrored Half Diamond Pattern = $
Mirrored Half Diamond Star 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.