print triangle of star using php
1) first loop considering $i as row and $j as column ,where total number of row is 4 and column is 7.
2) second is print * as passing the condition as following.
CODE:
for($i=1;$i<=4;$i++){
for($j=1;$j<=7;$j++){
if($i==1 && $j==4)
{
echo "*";
} else if(($j==3 || $j==5)&& $i==2 )
{
echo "*";
}else if(($j==2||$j==6)&&$i==3)
{
echo "*";
} else if(($j==1||$j==7)&&$i==4){
echo "*";
}
else{
echo " ";
}
}
echo "\n";
}
2) second is print * as passing the condition as following.
CODE:
for($i=1;$i<=4;$i++){
for($j=1;$j<=7;$j++){
if($i==1 && $j==4)
{
echo "*";
} else if(($j==3 || $j==5)&& $i==2 )
{
echo "*";
}else if(($j==2||$j==6)&&$i==3)
{
echo "*";
} else if(($j==1||$j==7)&&$i==4){
echo "*";
}
else{
echo " ";
}
}
echo "\n";
}
Comments
Post a Comment