12,621,150 members (31,512 online)
Rate this:
See more:
how much this loop swing ??

for ( int i=0 ; i<=10 ; i=i+2)
for ( int j=2 ; j<9 ;++j,j++)

A) 24
B) 35
C) 42
D) 20

the key question said A is right answer but how it calculate in data structure ? how the loop multiply then? please help me to solve it ... many thanks.
Posted 27-Nov-12 10:50am
ryanb31 27-Nov-12 15:52pm

What?
lida zar 27-Nov-12 15:56pm

how much this loop swing ? in data structure we studied for example

for(int i=0 ; i<10 ; i++)
for (int j=0 ; j<10 ; j++)

so it calculate like 10 * 10 = 100 so 100 times it swing ... now how much it swing ?
Sergey Alexandrovich Kryukov 27-Nov-12 17:30pm

Why, why asking such question?! Write it and execute it; it will tell you the answer.
--SA
lida zar 28-Nov-12 4:55am

so much angry u seem always with me ... im only a student ... y u think i should know everything ...

Nobody knows everything, but as a student you are supposed to know some minimum to pass the test, as simple as that. If you are going to protect yourself instead of learning, guess who is the looser? Eventually, you need to stop whining and start working hard, doing it by yourself. Or loose.

The student is not "only a student". Being a student is a big responsibility and hard work. If you consider yourself "only a student", as something minor, better don't consider yourself a student at all. I cannot be possibly angry with you in principle. I am sorry for you -- you are going nowhere, wasting time, probably money, and still don't have an idea what to do.

Rather, I'm angry with myself -- you are suffering, apparently, and I cannot see a way to help. What you really might need is a big kick, if it could get you to work. Maybe, kick yourself. But first, you need somehow to recognize yourself a decent person, a powerful learner and worker...

--SA

Rate this:

## Solution 2

If you are now learning the loops, I guess you have already learned the typical "Hello world", so if you don't want/can't do the maths... why don't you use the previous lessons and code it in an easy program to print out the values of the loop at each "swing"?

```int k = 1;
for ( int i=0 ; i<=10 ; i=i+2)
{
for (int j = 2; j < 9; ++j, j++)
{
Console.WriteLine("i = " + i + ", j = " + j + ", k = " + k);
k++;
}
}
```

That is the easiest way to find it out on your own and its infinitelly faster than asking in the internet, even in such a popular and/or populated place as CP

Another big advantage is... if you investigate the things on your own (applying the knowledge you already have), you will remember them easier than just getting the answer from another person.
v2
Nelek 28-Nov-12 3:41am

OP's comment moved from non-solution below
thanks for all ur helping but sometimes in new lessons i really dnt know how to program ... so here i learn it by good friends like u ...its my pleasure to use of ur knowledge as im in the start of my way ... and need many time to convert a gud one in c# like u :)anyways thanks very very much.
Rate this:

## Solution 1

You are obviously at an early stage of your programming career, maybe you should spend more time reading your notes.

However, you can work out the answer to this problem quite simply with pen and paper (same as the other one you asked). Just write down the starting values of the variables in each expression, then do the calculation to increment each one, counting until the test breaks the loop. At that point you will have the number of times each loop repeats. Multiply the two together and you get the answer.
HabeshaMan 27-Nov-12 18:11pm

Nice one.
Nelek 28-Nov-12 3:41am

OP's comment moved from non-solution below
thanks for all ur helping but sometimes in new lessons i really dnt know how to program ... so here i learn it by good friends like u ...its my pleasure to use of ur knowledge as im in the start of my way ... and need many time to convert a gud one in c# like u :)anyways thanks very very much.
Richard MacCutchan 28-Nov-12 5:22am

You need to learn and practice how to read the code, and think about it in logical ways. Writing things on paper often helps to make the logic clear, and gets things set in your mind for the next time. This only comes with lots of practice, but helps you in the long run.

Another suggestion: don't use childish txtspk (u, ur, gud ...) in these forums. If you want to be taken seriously then write properly spelt words; the spellchecker will help you.

Top Experts
Last 24hrsThis month
 OriginalGriff 310 ppolymorphe 225 Midi_Mick 190 Jochen Arndt 185 CPallini 143
 OriginalGriff 679 ppolymorphe 295 CPallini 243 Richard MacCutchan 218 Jochen Arndt 195