Signup/Sign In

C++ Program To Print Diamond Pattern Using *

Here our task is to print the required pattern without actually writing it manually. We will see how to do this for a diamond pattern. The simplest case will be to make the pattern using * only.

Following is the program to print diamond using *.

#include<iostream>
using namespace std;

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

    cout << "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++)
        {
            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++)
        {
            cout << "*";
        }
        cout << "\n";
    }
	
 	return 0;
}


Enter Diamond Star Pattern Row = 5
Diamond Star Pattern
*
***
*****
*******
*********
*******
*****
***
*

Conclusion

As for the implementation part, we can use alphabets, or any other symbol for the pattern but the general will remain the same for always.



About the author:
Nikita Pandey is a talented author and expert in programming languages such as C, C++, and Java. Her writing is informative, engaging, and offers practical insights and tips for programmers at all levels.