# PLS Help!!

Discussion in 'C' started by Robin_MT, Nov 7, 2008.

1. ### Robin_MTNew Member

Joined:
Nov 7, 2008
Messages:
1
0
Trophy Points:
0
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.

2. ### xpi0t0sMentor

Joined:
Aug 6, 2004
Messages:
3,009
203
Trophy Points:
63
Occupation:
Senior Support Engineer
Location:
England
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?

3. ### back from retirementNew Member

Joined:
Nov 9, 2008
Messages:
72
1
Trophy Points:
0
Occupation:
Student, UG 1st Yr., Jadavpur University
Location:
Uttarpara, West Bengal, India
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 @

4. ### xpi0t0sMentor

Joined:
Aug 6, 2004
Messages:
3,009
203
Trophy Points:
63
Occupation:
Senior Support Engineer
Location:
England
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).

5. ### back from retirementNew Member

Joined:
Nov 9, 2008
Messages:
72
1
Trophy Points:
0
Occupation:
Student, UG 1st Yr., Jadavpur University
Location:
Uttarpara, West Bengal, India
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....

6. ### xpi0t0sMentor

Joined:
Aug 6, 2004
Messages:
3,009
203
Trophy Points:
63
Occupation:
Senior Support Engineer
Location:
England
yeah, but sorting has nothing to do with the original post...

Joined:
Nov 9, 2008
Messages:
72