C++ Program to Print H Star Pattern

Write a C++ program to print H star pattern using for loop.

#include<iostream>
using namespace std;

int main()
{
	int rows, i, j, k, l;

	cout << "Please Enter H Pattern Rows = ";
	cin >> rows;

	cout << "Printing H Star Pattern\n";

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

	for (i = 1; i <= rows - 1; i++)
	{
		for (j = rows - 1; j >= i; j--)
		{
			cout << "*";
		}
		for (k = 1; k <= i * 2; k++)
		{
			cout << " ";
		}
		for (l = rows - 1; l >= i; l--)
		{
			cout << "*";
		}
		cout << "\n";
	}
}
C++ Program to Print H Star Pattern

This C++ program displays the alphabet H pattern of stars using a while loop.

#include<iostream>
using namespace std;

int main()
{
	int rows, i, j, k, l;

	cout << "Please Enter H Pattern Rows = ";
	cin >> rows;

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

	i = 1;
	while (i <= rows - 1)
	{
		j = rows - 1;
		while (j >= i)
		{
			cout << "*";
			j--;
		}
		k = 1;
		while (k <= i * 2)
		{
			cout << " ";
			k++;
		}
		l = rows - 1;
		while (l >= i)
		{
			cout << "*";
			l--;
		}
		cout << "\n";
		i++;
	}
}
Please Enter H Pattern Rows = 10
Printing H Star Pattern
*                  *
**                **
***              ***
****            ****
*****          *****
******        ******
*******      *******
********    ********
*********  *********
********************
*********  *********
********    ********
*******      *******
******        ******
*****          *****
****            ****
***              ***
**                **

C++ Program to Print H Star Pattern using a do while loop

#include<iostream>
using namespace std;

int main()
{
	int rows, i, j, k, l;

	cout << "Please Enter H Pattern Rows = ";
	cin >> rows;

	cout << "Printing H Star Pattern\n";
	i = 1;
	do
	{
		j = 1;
		do
		{
			cout << "*";
		} while (++j <= i);
		k = i * 2;
		while (k <= rows * 2 - 1)
		{
			cout << " ";
			k++;
		}
		l = 1;
		do
		{
			cout << "*";
		} while (++l <= i);
		cout << "\n";
	} while (++i <= rows);

	i = 1;
	do
	{
		j = rows - 1;
		do
		{
			cout << "*";
		} while (--j >= i);
		k = 1;
		do
		{
			cout << " ";
		} while (++k <= i * 2);
		l = rows - 1;
		do
		{
			cout << "*";
		} while (--l >= i);
		cout << "\n";
	} while (++i <= rows - 1);
}
Please Enter H Pattern Rows = 13
Printing H Star Pattern
*                        *
**                      **
***                    ***
****                  ****
*****                *****
******              ******
*******            *******
********          ********
*********        *********
**********      **********
***********    ***********
************  ************
**************************
************  ************
***********    ***********
**********      **********
*********        *********
********          ********
*******            *******
******              ******
*****                *****
****                  ****
***                    ***
**                      **
*                        *

In this C++ example, HPattern function allows user to enter the character and prints the H pattern of the given character.

#include<iostream>
using namespace std;

void HPattern(int rows, char ch)
{
	int i, j, k, l;

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

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

int main()
{
	int rows;
	char ch;

	cout << "Please Enter H Pattern Rows = ";
	cin >> rows;

	cout << "Enter Character for H Pattern = ";
	cin >> ch;

	cout << "Printing H Pattern\n";
	HPattern(rows, ch);
}
Please Enter H Pattern Rows = 15
Enter Character for H Pattern = &
Printing H Pattern
&                            &
&&                          &&
&&&                        &&&
&&&&                      &&&&
&&&&&                    &&&&&
&&&&&&                  &&&&&&
&&&&&&&                &&&&&&&
&&&&&&&&              &&&&&&&&
&&&&&&&&&            &&&&&&&&&
&&&&&&&&&&          &&&&&&&&&&
&&&&&&&&&&&        &&&&&&&&&&&
&&&&&&&&&&&&      &&&&&&&&&&&&
&&&&&&&&&&&&&    &&&&&&&&&&&&&
&&&&&&&&&&&&&&  &&&&&&&&&&&&&&
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
&&&&&&&&&&&&&&  &&&&&&&&&&&&&&
&&&&&&&&&&&&&    &&&&&&&&&&&&&
&&&&&&&&&&&&      &&&&&&&&&&&&
&&&&&&&&&&&        &&&&&&&&&&&
&&&&&&&&&&          &&&&&&&&&&
&&&&&&&&&            &&&&&&&&&
&&&&&&&&              &&&&&&&&
&&&&&&&                &&&&&&&
&&&&&&                  &&&&&&
&&&&&                    &&&&&
&&&&                      &&&&
&&&                        &&&
&&                          &&
&                            &