Hello all,
I have always had problems with loop tracking problems, I seem to understand how the loop runs and when it ends and the general idea of how it works. However, when I take a programming test and I need to track the output of a short loop, I fail most of the time. Can someone please help me? or give me some strategy tips?
The problem below is an example, I need to find the output of SUM without a computer, just using logic and a pencil and paper.
This is what I got for my i, and sum;
i
0
3
9
12
sum:
0
3
6
9
12
So in my attempt: sum= 12 but the correct answer is sum=30.
Code:int main () { int sum=0, i=0; while (i <=12) { sum = sum +i; // before this read sum=sum+1 which was a typo:/ i= i+3; } printf("%d", sum);