C++ Program to Print Inverted V Star Pattern

Write a C++ program to print inverted V star pattern or the half diamond inside a square star pattern using for loop.

#include<iostream>
using namespace std;

int main()
{
	int rows;

	cout << "Enter Inverted V Shape Star Pattern Rows = ";
	cin >> rows;

	cout << "Printing Inverted V Shape Star Pattern\n";

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

This C++ program prints the inverted V pattern of stars using a while loop.

#include<iostream>
using namespace std;

int main()
{
	int rows;

	cout << "Enter Inverted V Shape Star Pattern Rows = ";
	cin >> rows;

	cout << "Inverted V Shape Star Pattern\n";

	int i = rows;
	while (i >= 1)
	{
		int j = 1;
		while (j <= i)
		{
			cout << "*";
			j++;
		}
		int k = 1;
		while (k <= 2 * (rows - i))
		{
			cout << " ";
			k++;
		}
		int l = 1;
		while (l <= i)
		{
			cout << "*";
			l++;
		}
		cout << "\n";
		i--;
	}
}
Enter Inverted V Shape Star Pattern Rows = 12
Inverted V Shape Star Pattern
************************
***********  ***********
**********    **********
*********      *********
********        ********
*******          *******
******            ******
*****              *****
****                ****
***                  ***
**                    **
*                      *

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

#include<iostream>
using namespace std;

int main()
{
	int i, rows;

	cout << "Enter Inverted V Shape Star Pattern Rows = ";
	cin >> rows;

	cout << "Inverted V Shape Star Pattern\n";

	i = rows;
	do
	{
		int j = 1;
		do
		{
			cout << "*";

		} while (++j <= i);
		int k = 1;
		while (k <= 2 * (rows - i))
		{
			cout << " ";
			k++;
		}
		int l = 1;
		do
		{
			cout << "*";
		} while (++l <= i);
		cout << "\n";
	} while (--i >= 1);
}
Enter Inverted V Shape Star Pattern Rows = 15
Inverted V Shape Star Pattern
******************************
**************  **************
*************    *************
************      ************
***********        ***********
**********          **********
*********            *********
********              ********
*******                *******
******                  ******
*****                    *****
****                      ****
***                        ***
**                          **
*                            *

In this C++ pattern example, InvertedVShapePatternFun allows entering any character and displays the inverted V of a given character.

#include<iostream>
using namespace std;

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

int main()
{
	int rows;
	char ch;
	
	cout << "Enter Character for Inverted V Pattern = ";
	scanf("%c", &ch);

	cout << "Enter Inverted V Shape Star Pattern Rows = ";
	scanf("%d", &rows);

	cout << "Inverted V Shape Star Pattern\n";
	InvertedVShapePatternFun(rows, ch);
}
Enter Character for Inverted V Pattern = $
Enter Inverted V Shape Star Pattern Rows = 17
Inverted V Shape Star Pattern
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
$$$$$$$$$$$$$$$$  $$$$$$$$$$$$$$$$
$$$$$$$$$$$$$$$    $$$$$$$$$$$$$$$
$$$$$$$$$$$$$$      $$$$$$$$$$$$$$
$$$$$$$$$$$$$        $$$$$$$$$$$$$
$$$$$$$$$$$$          $$$$$$$$$$$$
$$$$$$$$$$$            $$$$$$$$$$$
$$$$$$$$$$              $$$$$$$$$$
$$$$$$$$$                $$$$$$$$$
$$$$$$$$                  $$$$$$$$
$$$$$$$                    $$$$$$$
$$$$$$                      $$$$$$
$$$$$                        $$$$$
$$$$                          $$$$
$$$                            $$$
$$                              $$
$                                $