*
***
*****
*******
*********
*******
*****
***
*
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend4days leftRegister
VulpesRank #55 · 29.2K reputationPosted Nov 2, 2012, 12:47 PM EDT
ahmed sami50 reputationPosted Nov 2, 2012, 1:02 PM EDT
thank you ..
but can you explain the code please ?
couse i misunderstand it !!!
VulpesRank #55 · 29.2K reputationPosted Nov 2, 2012, 1:14 PM EDT
Each row will begin with (4 - row) spaces followed by (2 * row + 1) asterisks and a new line character
So:
row 0 -> 4 spaces + 1 asterisk + '\n'
row 2 -> 2 spaces + 5 asterisks + '\n'
row 3 -> 1 space + 7 asterisks + '\n'
row 4 -> 0 spaces + 9 asterisks + '\n'
This part of the code then prints the last 4 rows of the diamond:
Each row will begin with (row + 1) spaces followed by (7 - 2 * row) asterisks and a new line character.
So:
There are some fancier ways of doing this but this one is (fairly) easy to understand :)
ahmed sami50 reputationPosted Nov 2, 2012, 1:29 PM EDT
you are a Genius !!
thank you very much ..
^_^