Q:

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

0

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

All Answers

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

<?php
$n=5;
for($i=1; $i<=$n; $i++)
{
for($j=1; $j<=$i; $j++)
{
echo ' * ';
}
echo '\n';
}
for($i=$n; $i>=1; $i--)
{
for($j=1; $j<=$i; $j++)
{
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