Skip to content

Add up 1 to 100 · ⁨从 1 加到 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 · ⁨IGCSE、A-Level⁩ & AP · ⁨与 AP⁩