1
0

More than 1 year has passed since last update.

【PHP初級㉙】for文応用1

Last updated at Posted at 2022-07-11

[問題]  (参照:http://www.cc.kyoto-su.ac.jp/~mmina/bp1/hundredKnocksPrimary.html)
整数値を5回入力させ、それらの値の合計を表示するプログラムを繰り返しを使って作成しなさい。

コード

for($m = 1; $m <= 5; $m++){
    $a = intval(fgets(STDIN));
    $i[] = $a; 
}
echo array_sum($i);


5
2
3
9
10  と入力

結果

29
1
0
3

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