anonymous No title
No License PHP
2020年11月14日
Copy
<!DOCTYPE html>
<html lang="ja">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>分数の計算を行う</title>
</head>

<body>
  <h1>分数の計算を行います</h1>
  <form action="index.php" method="POST">
    分数① <input type="text" name="molecule1" required> /
    <input type="text" name="denominator1" required>
    <br>
    <br>
    分数② <input type="text" name="molecule2" required> /
    <input type="text" name="denominator2" required>
    <hr>
    <input type="submit" value="分数①+分数②">
  </form>

  <?php if (isset($_POST['molecule1'])) : ?>
    <?php
    $molecule1 = $_POST['molecule1'];
    $denominator1 = $_POST['denominator1'];
    $molecule2 = $_POST['molecule2'];
    $denominator2 = $_POST['denominator2'];

    $denominator = $denominator1 * $sdenominator2;
    $molecule = ($molecule1 * $denominator2) + ($molecule2 * $denominator1);

    echo '分数① ' . $molecule1 . '/' . $denominator1 . ' と ';
    echo '分数② ' . $molecule2 . '/' . $denominator2 . ' 計算結果 ';
    $num1 = $molecule;
    $num2 = $denominator;
    ?>
    <?php while ($num1 % $num2 !== 0) : ?>
      <?php
      $num3 = $num1 % $num2;
      $num1 = $num2;
      $num2 = $num3;
      ?>
    <?php endwhile; ?>

    <?php
    $molecule /= $num2;
    $denominator /= $num2;
    $integer = (int) ($molecule / $denominator);
    ?>
    <?php if ($molecule < $denominator) : ?>
      <?= '分数だけ' . $molecule . '/' . $denominator; ?>
    <?php elseif ($molecule % $denominator === 0) : ?>
      <?= '整数だけ' . $integer; ?>
    <?php else : ?>
      <?= '帯分数' . $integer . ' ' .  ($molecule - $integer * $denominator) . '/' . $denominator; ?>
    <?php endif; ?>
  <?php endif; ?>
</body>

</html>
<!DOCTYPE html>
<html lang="ja">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>分数の計算を行う</title>
</head>

<body>
  <h1>分数の計算を行います</h1>
  <form action="index.php" method="POST">
    分数① <input type="text" name="molecule1" required> /
    <input type="text" name="denominator1" required>
    <br>
    <br>
    分数② <input type="text" name="molecule2" required> /
    <input type="text" name="denominator2" required>
    <hr>
    <input type="submit" value="分数①+分数②">
  </form>

  <?php if (isset($_POST['molecule1'])) : ?>
    <?php
    $molecule1 = $_POST['molecule1'];
    $denominator1 = $_POST['denominator1'];
    $molecule2 = $_POST['molecule2'];
    $denominator2 = $_POST['denominator2'];

    $denominator = $denominator1 * $sdenominator2;
    $molecule = ($molecule1 * $denominator2) + ($molecule2 * $denominator1);

    echo '分数① ' . $molecule1 . '/' . $denominator1 . ' と ';
    echo '分数② ' . $molecule2 . '/' . $denominator2 . ' 計算結果 ';
    $num1 = $molecule;
    $num2 = $denominator;
    ?>
    <?php while ($num1 % $num2 !== 0) : ?>
      <?php
      $num3 = $num1 % $num2;
      $num1 = $num2;
      $num2 = $num3;
      ?>
    <?php endwhile; ?>

    <?php
    $molecule /= $num2;
    $denominator /= $num2;
    $integer = (int) ($molecule / $denominator);
    ?>
    <?php if ($molecule < $denominator) : ?>
      <?= '分数だけ' . $molecule . '/' . $denominator; ?>
    <?php elseif ($molecule % $denominator === 0) : ?>
      <?= '整数だけ' . $integer; ?>
    <?php else : ?>
      <?= '帯分数' . $integer . ' ' .  ($molecule - $integer * $denominator) . '/' . $denominator; ?>
    <?php endif; ?>
  <?php endif; ?>
</body>

</html>

Output

Run
年末年始は機械学習・深層学習を勉強しませんか?
No one still commented. Please first comment.
年末年始は機械学習・深層学習を勉強しませんか?
広告
未経験から最短でエンジニアへの転職を目指すなら