Skip to content

Instantly share code, notes, and snippets.

@benznest
Created October 28, 2018 07:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save benznest/699fe927d44e622ef1e0de3b9408a2cc to your computer and use it in GitHub Desktop.
Save benznest/699fe927d44e622ef1e0de3b9408a2cc to your computer and use it in GitHub Desktop.
การบ้านปริ้นสามเหลี่ยม php
<?php
$rows = 10;
// Rectangle Normal
for($i=0; $i<$rows; $i++){
for($j=0; $j<$rows; $j++){
echo"O";
}
echo"<br>";
}
echo"<br>";
// Triangle A
for($i=0; $i<$rows; $i++){
for($j=0; $j<$i; $j++){
echo"O";
}
echo"<br>";
}
echo"<br>";
// Triangle B
for($i=0; $i<$rows; $i++){
for($j=$i; $j<$rows; $j++){
echo"O";
}
echo"<br>";
}
echo"<br>";
// Triangle C
for($i=0; $i<$rows; $i++){
for($j=$rows - $i ; $j<$rows; $j++){
echo"<font color='white'>O</font>";
}
for($j=$i; $j<$rows; $j++){
echo"O";
}
echo"<br>";
}
echo"<br>";
// Triangle D
for($i=0; $i<$rows; $i++){
for($j=$i ; $j<$rows; $j++){
echo"<font color='white'>O</font>";
}
for($j=$rows - $i; $j<$rows; $j++){
echo"O";
}
echo"<br>";
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment