Thank you :cheesy:
Problem #1:
So for this problem my answer would be 10, correct?
Correct.
Problem #2:So my answers would be...4 and 16?
Well, the value of 'a' would first be 2, then 4 and then 16, so you're correct. But I wouldn't call it answers.
Nick Evan
Not a Llama
10,112 posts since Oct 2006
Reputation Points: 4,142
Solved Threads: 403
I'm not really sure how to do this one. i++ = 1, so the first time through a= 2, i=1. Then a=3, i=2 and that's where the program would end, right? Sorry if that doesn't make sense.
No, the i++ is executed AFTER a=a+i, so it starts with a =2 & i=0
Then: while (i<=5){ i starts at '0' and ends with '5', so the code will be executed 6 times:
times a i | new-a (output..)
---------------------
1 2 0 | 2
2 2 1 | 3
3 3 2 | 5
4 5 3 | 8
5 8 4 | 12
6 12 5 | 17
That's it!
Nick Evan
Not a Llama
10,112 posts since Oct 2006
Reputation Points: 4,142
Solved Threads: 403
for the original problems, the answers should be 20 and 256. Since it's a loop, it'll repeat until the condition is false (i.e. until a>12 and a>25 respectively).
Infarction
Posting Virtuoso
1,580 posts since May 2006
Reputation Points: 683
Solved Threads: 53
You're right, I was totaly off.. :o Sorry bout that one....
Nick Evan
Not a Llama
10,112 posts since Oct 2006
Reputation Points: 4,142
Solved Threads: 403