Ask Your Question By Comment We Will Give You Better Solution Soon

Wednesday 5 February 2014

How To Print Stars in PHP

Q1. Print star in descending order.
 
<?php
for($i=0;$i<=5;$i++){
for($j=5-$i;$j>=1;$j--){
echo "*&nbsp;";
}
echo "<br>";
}
?>

Output:
*****
****
***
**
*

Q2. print star in ascending order.

<?php
 for($i=1;$i<=5;$i++){
 for($j=5;$j>=0;$j--){
 if($j<$i){
 echo "*&nbsp";
 }
 }echo "<br>";
 }

 ?>
 Output:
*
**
***
****
*****

No comments:

Post a Comment