Question Detail

COM 101 COM 101 Past Questions Objective Question

Question

Given the following segment of code: x=0 For i = 1 To 5 x=x+i Next i What will be the final value of x?
Options
A 2
B 14
C 15
Correct Answer
D 55
Correct Answer

Option C is the correct answer.

Detailed Explanation

The loop adds the value of i to x each iteration. So x = 0 + 1 + 2 + 3 + 4 + 5 = 15.

Hint

It's the sum of numbers from 1 to 5.

Question Info