LoginSignup
1
0

More than 1 year has passed since last update.

【PHP基礎復習11】配列要素の和

Posted at

[問題]
1から入力値Aまで1ずつ増えていく整数の値の和を求めよ。
なお、Aは2以上とする。

コード

$input1 = fgets(STDIN);
$input2 = range(1,$input1);
echo array_sum($input2),PHP_EOL;

↓ 140と入力

結果

9870

☆ range(a,b)
→ aからbまでの配列

☆array_sum()
→ 配列の要素の和

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