Consider the following Pseudo-code segment:
k:=0
for $i_1$:=1 to n
for $i_2$ := 1 to $i_1$
:
for $i_m$:=1 to $i_{m-1}$
k:=k+1
The value of k after the execution of this code shall be
Let n=3 and m=2
so, i1:1 to 3
i2=1 to i1
Now, when i1=1, i2 iterates only for i2=1 so k=1
when i1=2, i2 iterates for i2=1 and i2=2so k=3
when i1=3, i2 iterates for i2=1,i2=2,i2=3 so k=6
=>K=6
64.3k questions
77.9k answers
244k comments
80.0k users