Yes you were close man, but close to what? Loops are difficult, or can you not figure out the meaning of the word move, cause the answer was in your code, but it needed to be moved.
Printable View
Yes you were close man, but close to what? Loops are difficult, or can you not figure out the meaning of the word move, cause the answer was in your code, but it needed to be moved.
Note that this:
doesn't do at all what you think, since i^2 is i xor 2, not i squared.Code:for (i =1; i < 12; i +=i^2)
And I really don't see any reason why the loop should be a while-loop rather than a for-loop. Think about what the while-loop variant posted does, then try to produce a for-loop that does the same thing.
--
Mats
Somewhat, yes, but not close enough, for now :)Quote:
See I knew I was close.
Incidentally, lala123's example would be better written as:
The temporary x is not needed, and the for loop more clearly expresses how the loop iterates ("from i=1 to i=12", instead of "while i is less than or equal to 12").Code:int i;
for (i = 1; i <= 12; ++i)
{
printf("%d ", i * i);
}
EDIT:
matsp has a good point: try it out yourself first. I have blanked out my code example, but of course you can still read it to check your answer.