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】ゼロ・プラス・マイナスを繰り返し判定する

Last updated at Posted at 2021-05-10
<?php
    $count = trim(fgets(STDIN));
    
     echo "受け取った整数".$count . "\n";

    for ($i = 0; $i < $count; $i++) {
        $number = trim(fgets(STDIN));

        if ($number == 0) {
            echo $number . "は0\n";
        } elseif ($number > 0) {
           echo $number . "はプラス\n";
        } else {
           echo $number . "はマイナス\n";
        }
    }
?>

  1. 標準入力から整数を 1 個受け取る

  2. 受け取った整数を表示する

  3. 受け取った整数回分、以下の処理を繰り返す

a. さらに標準入力から整数を 1 個受け取る

b. その整数が 0 の場合、以下のメッセージを表示する

c. その整数が 0 より大きい場合、以下のメッセージを表示する

d. それ以外の場合、以下のメッセージを表示する

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?