Add up 1 to 100 · บวก 1 ถึง 100
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 หยุด.卡尔ฟรี德里希高斯 (Carl Friedrich Gauss) ในวัยเด็ก reportedly พบคำตอบนี้ในใจโดยการจับคู่ 1 + 100, 2 + 99 และอื่นๆ
Use a for loop to add up every whole number from 1 to 100, then print the total once. · ใช้ for ลูปบวกเลขเต็มทุกตัวตั้งแต่ 1 ถึง 100 แล้วพิมพ์ผลรวมทั้งหมดทีเดียว
Click Run to see the output here. · คลิก Run เพื่อดูผลลัพธ์ที่นี่