Skip to main content
11 events
when toggle format what by license comment
May 23, 2017 at 12:40 history edited CommunityBot
replaced http://stackoverflow.com/ with https://stackoverflow.com/
Mar 7, 2016 at 12:45 comment added Edward I've added to my answer to show exactly what I mean.
Mar 7, 2016 at 12:45 history edited Edward CC BY-SA 3.0
added full code for column-first
Mar 7, 2016 at 8:17 comment added user31782 I believe you meant subtract number*( maxrows*(maxcols-1) ) not subtractnumber*( (maxrows*maxcols) - 1 ). But even if you meant the former then we have to subtract number once more. Say the last number printed in a row is X then the first number in the next row should be X - number*( ((maxcols-1)*maxrows) - 1).
Mar 6, 2016 at 14:53 comment added Edward Sure. For each item in a row, add number*maxrows, and for each new row subtract number*(maxrows*maxcols-1). Both are "loop invariants" and can be calculated once before the loop begins.
Mar 6, 2016 at 14:33 comment added user31782 @Edward In my third version's aliter program which prints the multiplication table vertically. Can we replace number*(row + maxrows*col) with some statement which uses addition rather than multiplication to achieve the same function?
Mar 6, 2016 at 14:27 comment added user31782 @Tim I only knew that int x=i++ would give pre-incremented value and int x=++i would give incremented value. I didn't know that the former one uses only one register and the later one two.
Mar 6, 2016 at 14:25 comment added Max Payne @user31782 If you do some search over the net, you'll find most of the questions have already been answered on other SE sites: Regarding ++i and i++ : Stackoverflow
Mar 6, 2016 at 14:20 comment added Edward Yes, exactly because you don't need to save the value use ++i instead. The difference is that ++i increments and then returns that incremented value (typically needing only a single register) while i++ increments but returns the original, unincremented value (typically requiring two registers). Not a big deal, as I've said, but why not get into good habits early?
Mar 6, 2016 at 14:16 comment added user31782 I've some doubt on Prefer ++i to i++ in loops section. AFAIK we never need to save pre-incremented value in for loop. Because the incrementation is always done at the end of the loop. ++i or i++ both will function same in every case of for loop.
Mar 6, 2016 at 14:01 history answered Edward CC BY-SA 3.0