Question on: SS3 ICT - Basic Programing III
Write a BASIC program that calculates the sum of all even numbers from 1 to 50 using a loop
View related lesson
Ask EduPadi AI for a detailed answer
Here is a BASIC program that calculates the sum of even numbers from 1 to 50 using a FOR-NEXT loop:
basic Copy code
total = 0
FOR i = 2 TO 50 STEP 2
total = total + i
NEXT i
PRINT "Sum of even numbers from 1 to 50: "; total
This program initializes a total variable to 0 and then uses a FOR-NEXT loop with a step of 2 to iterate through even numbers from 2 to 50, adding them to the total variable. Finally, it prints the sum.
Add your answer
Please share this, thanks!
No responses