Computer Science, asked by arindamkorche, 4 days ago

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 anindyaadhikari13
7

Answer:

  • The output for the given program is 55.

Explanation:

  1. CLS
  2. SUM = 0
  3. FOR I = 1 TO 10 STEP 1
  4.    SUM = SUM + I
  5. NEXT I
  6. PRINT SUM
  7. 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