2. What will be the output for the following program? CLS Sum = 0 FOR I = 1 TO 10 Sum = Sum + I NEXT I PRINT Sum A)22 B)10 C)55
Answers
Answered by
7
Answer:
- The output for the given program is 55.
Explanation:
- CLS
- SUM = 0
- FOR I = 1 TO 10 STEP 1
- SUM = SUM + I
- NEXT I
- PRINT SUM
- END
- Line 1: Clears the screen.
- Line 2: A new variable named 'SUM' is created and it is initialised with 0.
- Line 3: A loop is created which iterates from I = 1 to 10.
- Line 4: The value of 'I' is added to the sum after each iteration.
- Line 5: End of for loop.
- Line 6: The value of sum is displayed on the screen.
- Line 7: End of program.
From here, we can say that the variable SUM stores the sum of first 10 natural numbers.
→ SUM = 1 + 2 + ... + 10
→ SUM = 55
→ So, the output is 55.
See attachment for verification.
Attachments:
Similar questions
Math,
2 days ago
Math,
2 days ago
Chemistry,
4 days ago
Physics,
8 months ago
Social Sciences,
8 months ago