Skip to content · ⁨コンテンツへスキップ⁩

Add up 1 to 100

English

Add up 1 to 100

Add every whole number from 1 to 100 and print the result.

This is a running total: start at 0 and add the loop variable on every pass. The starter adds 1 to 10, so you only need to change where the range stops. The young Carl Friedrich Gauss is said to have found this answer in his head by pairing 1 + 100, 2 + 99 and so on.

日本語

1から100までの合計

1 から 100 までのすべての整数を加えて結果を出力します。

これは累計合計です: 0 で始め、各反復でループ変数を加算します。初期値として 1 を 10 に加えることで、range の停止位置を変えるだけで済みます。若いカル・フリードリヒ・ガウスは、1 + 100、2 + 99 などをペアにして頭の中でこの答えを導き出したと言われています。

Log in or create account · ⁨ログインまたはアカウント作成⁩

IGCSE, A-Level & AP