NastySwipy

Drawing Figures with Loops - Diamond

Feb 14th, 2018
170
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.66 KB | None | 0 0
  1. $num = intval(readline());
  2. echo str_repeat("-", ($num - 1) / 2) . str_repeat("*", $num & 1 ? 1 : 2) . str_repeat("-", ($num - 1) / 2) . "\n";
  3. for ($i = 1, $j = 0; $i < $num / 2; $i++, $j += 2) {
  4.     echo str_repeat("-", (($num - 1) / 2) - $i) . "*" . str_repeat("-", ($num & 1 ? 1 : 2) + $j) . "*" . str_repeat("-", (($num - 1) / 2) - $i) . "\n";
  5. }
  6. for ($i = 1, $j = 0; $i <= ($num - 3) / 2; $i++, $j += 2) {
  7.     echo str_repeat("-", $i) . "*" . str_repeat("-", round($num - 4) - $j) . "*" . str_repeat("-", $i) . "\n";
  8. }
  9. if ($num != 1 && $num != 2) {
  10.     echo str_repeat("-", ($num - 1) / 2) . str_repeat("*", $num & 1 ? 1 : 2) . str_repeat("-", ($num - 1) / 2);
  11. }
Advertisement
Add Comment
Please, Sign In to add comment