//This is PseudoCode
a := 1;
b := 2;
c := a + b;
sum := 0;
for i := 1 to 3 do
begin
inc(a); inc(b);
sum := sum + a + b;
sum := sum + c;
end;
writeln(sum);
What is the last result of sum ?
This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try
refreshing the page, (b) enabling javascript if it is disabled on your browser and,
finally, (c)
loading the
non-javascript version of this page
. We're sorry about the hassle.
a = 1 , b = 2 , c = a + b = 3; when i = 1 : inc(a) = a + 1 = 2; inc(b) = b + 1 = 3; sum = 0 + 2 + 3 = 5; sum = 5 + c = 5 + 3 = 8;
a = 2 , b = 3 , c = a + b = 5; when i = 2 : inc(a) = a + 1 = 3; inc(b) = b + 1 = 4; sum = 8 + 3 + 4 = 15; sum = 15 + c = 15 + 5 = 20;
a = 3 , b = 4 , c = a + b = 3 + 4 = 7; when i = 3 : inc(a) = a + 1 = 4; inc(b) = b + 1 = 5; sum = 20 + 4 + 5 = 29; sum = 29 + c = 29 + 7 = 36;
the looping has stopped and the last result of sum is 36 .