Q:

Create a script to construct the following pattern, using nested for loop

0

Create a script to construct the following pattern, using nested for loop.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

<?php
for($x=1;$x<=5;$x++)
{
   for ($y=1;$y<=$x;$y++)
    {
	 echo "*";
	    if($y< $x)
		 {
		   echo " ";
		 }
     }
 echo "\n";
}
?>

 

Sample Output:
*                                                           
* *                                                         
* * *                                                       
* * * *                                                     
* * * * *

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now