Answer to Question #329307 in C++ for Zaki

Question #329307

Write a C++ program that prints on the screen following diamond shape with given series of numbers.

1
Expert's answer
2022-04-16T06:48:35-0400
#include<iostream>

using namespace std;

int main()
{
	int i, j, rowNum, space;
	cout << "Enter the Number of Rows: ";
	cin >> rowNum;
	space = rowNum - 1;
	for (i = 1; i <= rowNum; i++)
	{
		for (j = 1; j <= space; j++)
			cout << " ";
		space--;
		for (j = 1; j <= (2 * i - 1); j++)
			cout << "*";
		cout << endl;
	}
	space = 1;
	for (i = 1; i <= (rowNum - 1); i++)
	{
		for (j = 1; j <= space; j++)
			cout << " ";
		space++;
		for (j = 1; j <= (2 * (rowNum - i) - 1); j++)
			cout << "*";
		cout << endl;
	}
	cout << endl;
	return 0;
}





Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS