Vivid Lust Posted July 25, 2008 Share Posted July 25, 2008 How can i make a pyramid of asterix with 41 stars in the last row???? so like: * *** ***** ******* etc Thanks for the help. Quote Link to comment https://forums.phpfreaks.com/topic/116552-pyramid-of-asterix/ Share on other sites More sharing options...
waynew Posted July 25, 2008 Share Posted July 25, 2008 echo ' * *** ***** *******'; LOL Quote Link to comment https://forums.phpfreaks.com/topic/116552-pyramid-of-asterix/#findComment-599309 Share on other sites More sharing options...
ignace Posted July 25, 2008 Share Posted July 25, 2008 lol, reminds of the times i was in class and had to do this horrible job in Java, VB.NET, C++, bweh :S for ($i = 1; $i <= 41; $i++) { for ($j = 0; $j < $i; $j++) { echo '*'; } echo '<br />'; } this will give you something like: * ** *** .. to get something like this: * ** *** you will most presumably need a table, as in php you don't have something like: drawer.pos(x, y) Quote Link to comment https://forums.phpfreaks.com/topic/116552-pyramid-of-asterix/#findComment-599310 Share on other sites More sharing options...
LemonInflux Posted July 25, 2008 Share Posted July 25, 2008 [pre] * *** ***** ******* ********* *********** ************* *************** ***************** ******************* ********************* *********************** ************************* *************************** ***************************** ******************************* ********************************* *********************************** ************************************* *************************************** *****************************************[/pre] Quote Link to comment https://forums.phpfreaks.com/topic/116552-pyramid-of-asterix/#findComment-599312 Share on other sites More sharing options...
Vivid Lust Posted July 25, 2008 Author Share Posted July 25, 2008 Thanks lol, heres this question where i had to do it in pascal, i had a while loop with the count going up by 2 each time and i had no idea how to print a line with that many asterix xd so i though php would give me an idea. Quote Link to comment https://forums.phpfreaks.com/topic/116552-pyramid-of-asterix/#findComment-599313 Share on other sites More sharing options...
LemonInflux Posted July 25, 2008 Share Posted July 25, 2008 I find it's easier just to do it manually Quote Link to comment https://forums.phpfreaks.com/topic/116552-pyramid-of-asterix/#findComment-599314 Share on other sites More sharing options...
JonnyThunder Posted July 25, 2008 Share Posted July 25, 2008 for ($x = 0; $x < 21; $x++) { $spacer = str_repeat(" ", (21 - $x)); $stars = str_repeat("*", ($x*2)+1); print $spacer . $stars . $spacer . "\n"; } Lol... you'd need to use a fixed sized font for it to display, and if it's for a webpage - perhaps use &NBSP; instead of a space! Quote Link to comment https://forums.phpfreaks.com/topic/116552-pyramid-of-asterix/#findComment-599317 Share on other sites More sharing options...
waynew Posted July 25, 2008 Share Posted July 25, 2008 I had to do this in Java. Quote Link to comment https://forums.phpfreaks.com/topic/116552-pyramid-of-asterix/#findComment-599332 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.