How can I output the below asterisks in rhombus shape in c++ using the least number of loops and variables. Maximum no. of stars = n (input taken from the user)
*
* *
* * * = n
* *
*
I tried doing it with just 2 loops but didn’t succeed plus the program is too complicated to understand so didn’t include it here.
So any algorithms you can think of?
This is a common question for education I believe, and thus a Google search is very helpful.
Here is a ready made solution in Visual C++ (as some people learn better from code examples, the choice is yours)…
http://www.softwareandfinance.com/Visual_CPP/Loops_Diamond_Pattern.html
EDIT: Trying to reduce the for loops and keeping the spacing between stars, this is my best effort…
ONLY 2 LOOPS USED: