(1) Program to print below format
*
* *
* * *
* * * *
* * * * *
* * * * * *
* * * * * * *
* * * * * * * *
* * * * * * * * *
<?php
?>
(2 ) Write a program to print the below format :
1 5 9
2 6 10
3 7 11
4 8 12
*
* *
* * *
* * * *
* * * * *
* * * * * *
* * * * * * *
* * * * * * * *
* * * * * * * * *
<?php
$rows=5; // number of row
for($i=1;$i<=$rows;$i++)
{
for($j=1;$j<=$i;$j++)
{
echo "*";
}
echo "<br />";
}
?>
(2 ) Write a program to print the below format :
1 5 9
2 6 10
3 7 11
4 8 12
<?php
for($i=1;$i<=4;$i++)
{
$i1=$i+4;
$i2=$i+8;
echo $i." ".$i1." ".$i2;
echo "<br />";
}
?>
for($i=1;$i<=4;$i++)
{
$i1=$i+4;
$i2=$i+8;
echo $i." ".$i1." ".$i2;
echo "<br />";
}
?>
(3) Write a program for this Pattern:
*****
* *
* *
* *
*****
* *
* *
* *
*****
<?php
for($i = 1; $i<=5; $i++){
for($j = 1; $j<=5; $j++){
if($i == 1 || $i == 5){
echo "*";
}
else if($j == 1 || $j == 5){
echo "*";
}
else {
echo " ";
}
}
echo "<br/>";
}
?>
for($i = 1; $i<=5; $i++){
for($j = 1; $j<=5; $j++){
if($i == 1 || $i == 5){
echo "*";
}
else if($j == 1 || $j == 5){
echo "*";
}
else {
echo " ";
}
}
echo "<br/>";
}
?>
No comments:
Post a Comment