Studytonight is now part of the GUVI universe. Explore GUVI →
🤩 New Cool Developer Tools for you. Explore →
FREE JavaScript Video Series Start Learning →
Signup/Sign In
Tests
MCQs to test your knowledge.
Compilers
Compilers to execute code in browser.
Index
LAST UPDATED: MARCH 14, 2022

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.

Learn to Code
Learn and practice coding side-by-side.
NEW
C language Course
115+ coding exercises
Javascript Course
85+ coding exercises

AltStyle によって変換されたページ (->オリジナル) /