Could someone explain how the answer was calculated

asked 2023-12-08 15:39:47 +0100

Júlia gravatar image

updated 2023-12-09 22:24:43 +0100

Max Alekseyev gravatar image

.

S = 0 
for k in [1..3]:
     S = S+k 
S = 2*S
S

Answer: 12

edit retag flag offensive close merge delete

Comments

$$(1+2+3)\cdot 2=12$$

Max Alekseyev gravatar imageMax Alekseyev ( 2023-12-09 22:25:30 +0100 )edit

Set S=0

In the for loop:

k=1, S=0+1=1

k=2, S=1+2=3

k=3, S=3+3=6

Set S=2 * S = 2 * 6 = 12

tolga gravatar imagetolga ( 2023-12-10 07:58:53 +0100 )edit