From d277c5b669daeb53294d8a8cc5913cf84595a825 Mon Sep 17 00:00:00 2001 From: m-takatsuki <26-m-takatsuki-webstar@it-college.co.jp> Date: Tue, 13 Oct 2026 13:42:20 +0900 Subject: [PATCH] =?UTF-8?q?Ex.3=20=E5=AE=8C=E4=BA=86=20Ex.5=20=E5=AE=8C?= =?UTF-8?q?=E4=BA=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Question08-Function/Ex03.php | 4 ++-- Question08-Function/Ex05.php | 28 +++++++++++++++++++++++++++- 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/Question08-Function/Ex03.php b/Question08-Function/Ex03.php index 2896b64..c19b402 100644 --- a/Question08-Function/Ex03.php +++ b/Question08-Function/Ex03.php @@ -7,10 +7,10 @@ * * 引数で渡された内容が偶数ならtrue、奇数ならfalseを返す関数 */ -function isEvenNumber ($x) +function isEvenNumber ($recive) // ↑引数はXだが21行目の指示はnumberで呼び出すことを意味している { - $result = (($x % 2 )=== 0); + $result = (($number % 2 )=== 0); return $result; } diff --git a/Question08-Function/Ex05.php b/Question08-Function/Ex05.php index e22ace2..3ed029e 100644 --- a/Question08-Function/Ex05.php +++ b/Question08-Function/Ex05.php @@ -7,7 +7,14 @@ * * 引数で渡された横の長さ(width)と縦の長さ(height)から、四角形の面積を返す関数 */ +function quadrangle($width, $height) +{ + $result = '面積は:' . ($width * $height); + return $result; +} +$width = 20; +$height = 50; /* TODO: * 以下の仕様で関数を作成してください @@ -17,7 +24,26 @@ * * 引数で渡された横の長さ(width)と縦の長さ(height)から、三角形の面積を返す関数 */ +function triangle($width, $height) +{ + $result = '面積は:' . ($width * $height / 2); + return $result; +} + +$width = 20; +$height = 50; + - // TODO: // 変数choiceの中が、1であれば四角形の面積を算出するメソッドを、2であれば三角形の面積を算出するメソッドを呼び出してください +$choice = 1; + +if ($choice == 1) { + $area = quadrangle($width, $height); + echo "四角形の面積: {$area}\n"; +} + +if ($choice == 2) { + $area = triangle($width, $height); + echo "三角形の面積: {$area}\n"; +}