Program in PHP:
function create_pyramid($limit) {
for($row = 1; $row < $limit; $row ++) {
for($j = 0; $j < $limit-$row; $j++){
echo " ";
}
for($k = 0; $k < ($row-1)*2+1; $k++){
echo "*";
}
echo 'break tag here';
}
$s = 2;
for($l=$row-1; $l>0; $l--){
for($m = 0;$m<$s; $m++){
echo " ";
}
for($n = 0; $n < ($l-1)*2-1; $n++){
echo "*";
}
echo 'break tag here';
$s++;
}
}
echo " break tag here" ;
create_pyramid(10);
Output:
function create_pyramid($limit) {
for($row = 1; $row < $limit; $row ++) {
for($j = 0; $j < $limit-$row; $j++){
echo " ";
}
for($k = 0; $k < ($row-1)*2+1; $k++){
echo "*";
}
echo 'break tag here';
}
$s = 2;
for($l=$row-1; $l>0; $l--){
for($m = 0;$m<$s; $m++){
echo " ";
}
for($n = 0; $n < ($l-1)*2-1; $n++){
echo "*";
}
echo 'break tag here';
$s++;
}
}
echo " break tag here" ;
create_pyramid(10);
Output:
* *** ***** ******* ********* *********** ************* *************** ***************** *************** ************* *********** ********* ******* ***** *** *
No comments:
Post a Comment