Ex.3 完了

Ex.5 完了
This commit is contained in:
2026-10-13 13:42:20 +09:00
parent cfe2332a76
commit d277c5b669
2 changed files with 29 additions and 3 deletions

View File

@@ -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;
}

View File

@@ -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";
}