*
**
***
I tried with for loops but no result;
Thanks in Advance
Try with this code,
<?php
echo '<p align="right">';
for($i=1;$i<=3;$i++)
{
echo str_repeat('*',$i);
echo "<br />";
}
echo "</p>";
?>
Check following code:
</pre>
<?php
for($i=0;$i<=5;$i++){
for($j=1;$j<=$i;$j++){
echo "* ";
}
echo "<br>";
}
?>
Output
*
* *
* * *
* * * *
* * * * *
* * * * * *
* * * * * * *
try this,
$num = 3;
for($r=1; $r<=$num; $r++)
{
for($sp=$num-$r; $sp>0; $sp--)
printf(" ");
for($c=$r; $c>=1; $c--)
echo("*");
echo("
");
}
OUTPUT
*
**
***
Here you go. In Java though. For someone who is checking later :)
public static void main(String args[]){
int i, j, k;
for(i=5;i>=1;i--)
{
for(j=1;j<i;j++)
{
System.out.print(" ");
}
for(k=5;k>=i;k--)
{
System.out.print("*");
}
System.out.println();
}
}
$height= 3;
$width=($height-1);
for($line=0;$line<$height;$line++){
for($space=$width-$line;$space>0;$space--){
echo " ";
}
for($star=($line+1);$star>0;$star--){
echo "*";
}
echo "
";
}
output:
*
**
***