Answer to Question #217266 in C++ for Abigail

Question #217266

2.16: Diamond Pattern


Write a <span style="text-decoration-line: none;">program</span> that displays the following pattern:




*


***


*****


*******


*****


***


*


1
Expert's answer
2021-07-15T02:45:41-0400
#include <iostream>
using namespace std;
int main()
{
int  i, j, n;
//Number of rows must be an odd number
n=7; //Let 9 be the number of rows
i= 1;
while(i <= n){
	j = 1;
	while(j <= i){
		cout << "* ";
		j++;
	}
	i+=2;
	cout << "\n";
}
i = 5; //Should be less than rows by 2
while( i >= 1){
	j = 1;
	while(j <= i){
		cout << "* ";
		j++;
	}
	
	cout << "\n";
	i -= 2;
}






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