PLS Help!!

Robin_MT's Avatar, Join Date: Nov 2008
Newbie Member
Can someone help me with C and C++ codes for a loop for summing 10 integers with odd indices only. Each integer is 32 bits. And another program without loop. and pls explain the effect of using loop and without loop.


Thanks in advance !!
xpi0t0s's Avatar, Join Date: Aug 2004
Mentor
How far have you got, and where are you stuck? Can you perform the task on paper?
Do you know how to store 10 integers?
Can you write a loop that sums 10 integers using both even and odd indices? Then you could modify that to add up just the odd ones.
What do you think is the difference between using a loop and not using a loop? If you didn't know in advance the number of integers to add up, how do you think you might do that without a loop?
back from retirement's Avatar, Join Date: Nov 2008
Contributor
I think the major difference that gonna occur for using loop or not using loop is regarding the runtime complexity....because both will have more or less same space complexity....am I right??

----------------
@ r k @
xpi0t0s's Avatar, Join Date: Aug 2004
Mentor
Dunno what you mean by "runtime complexity" and "space complexity". Using a loop means you can do the task a number of times that is not known at compile time. If you know the number of times you have to do the task at compile time then you can just repeat the statement N times, although it is neater to use a loop. The one with the loop will be slower than the one without, because you have the overhead of an increment, compare and jump on each iteration, so loop unrolling is a valid optimisation technique (AFTER profiling etc).
back from retirement's Avatar, Join Date: Nov 2008
Contributor
Oh dear.....probably u know it by an other term, but they are the facts for which a quick sort is better than a bubble sort....
xpi0t0s's Avatar, Join Date: Aug 2004
Mentor
yeah, but sorting has nothing to do with the original post...
back from retirement's Avatar, Join Date: Nov 2008
Contributor
I know, I know that sorting has nothing to do with the initial post....sorry for my bad english....but what I wanted is to point out the factors "runtime complexity" and "space complexity" by means of the example of sorting....