LoginSignup
1
0

More than 1 year has passed since last update.

【PHP基礎⑭】ループ処理-4.カウントダウン

Last updated at Posted at 2022-06-21

[問題]  (参照:http://www.cc.kyoto-su.ac.jp/~mmina/bp1/hundredKnocksBasic.html)
整数値を入力させ、入力値から0まで数を1ずつ減らして表示するプログラムを作成しなさい。
なお、入力値に0以下の値を入力した場合は考慮しなくてもよい。

コード

$a = intval(fgets(STDIN));
for($m = $a; $m >= 0; $m--){
    echo "$m \n";
}

↓「7」と入力

結果

7 
6 
5 
4 
3 
2 
1 
0 

☆1ずつ減らす→ $m--

1
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
1
0