0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

【php】1-100の範囲の乱数が奇数か偶数かを判定するプログラムを作成せよ

Posted at

1・1-100の範囲の乱数を取得し、変数 $rand に代入する
2・乱数の値を「$rand: [乱数]」と表示する
3・偶数が代入されていれば、「偶数です。」と表示する。
4・奇数が代入されていれば、「奇数です。」と表示する。

<?php
$rand = mt_rand(1, 100);
 
if ($rand % 2 === 0) {
  # 入力値が偶数ならば
  $result = '偶数';
} else {
  # 入力値が偶数でないならば(奇数ならば)
  $result = '奇数';
}
?>
<!DOCTYPE html>
<html lang="ja">
<head>
    <title>奇数・偶数の判定</title>
</head>
<body>
  <h1>奇数・偶数の判定</h1>
  <p>$rand: <?php echo $rand; ?></p>
  <p><?php echo $result; ?>です。</p>
</body>
</html>
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?