Go4Expert (http://www.go4expert.com/)
-   C (http://www.go4expert.com/forums/c/)
-   -   PLS Help!! (http://www.go4expert.com/forums/pls-help-t15029/)

Robin_MT 7Nov2008 20:07

PLS Help!!
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 8Nov2008 14:14

Re: PLS Help!!
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 14Nov2008 20:29

Re: PLS Help!!
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 14Nov2008 23:22

Re: PLS Help!!
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 15Nov2008 11:47

Re: PLS Help!!
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 15Nov2008 16:54

Re: PLS Help!!
yeah, but sorting has nothing to do with the original post...

back from retirement 16Nov2008 11:49

Re: PLS Help!!
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....

All times are GMT +5.5. The time now is 05:42.