Write a BASIC program that calculates the sum o... - SS3 ICT Basic Programing III Question
Write a BASIC program that calculates the sum of all even numbers from 1 to 50 using a loop
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.
Please share this, thanks:
#SS3 #SS3
Add your answer
No responses