Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#
how much this loop swing ??
 
for ( int i=0 ; i<=10 ; i=i+2)
for ( int j=2 ; j<9 ;++j,j++)
 
the answer is :
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 9:50am
Comments
ryanb31 at 27-Nov-12 15:52pm
   
What?
lida zar at 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 at 27-Nov-12 17:30pm
   
Why, why asking such question?! Write it and execute it; it will tell you the answer.
--SA
lida zar at 28-Nov-12 4:55am
   
so much angry u seem always with me ... im only a student ... y u think i should know everything ...
Sergey Alexandrovich Kryukov at 28-Nov-12 9:51am
   
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...
 
Nobody denies to help you. But not to do your work. After all, it cannot help your at all, not matter how much people wanted to help.
 
--SA
Rate this: bad
good
Please Sign up or sign in to vote.

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++;
   }
}
Console.ReadLine();
 
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.
  Permalink  
v2
Comments
Nelek at 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: bad
good
Please Sign up or sign in to vote.

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.
  Permalink  
Comments
HabeshaMan at 27-Nov-12 18:11pm
   
Nice one.
Nelek at 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 at 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.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 _Amy 310
1 OriginalGriff 294
2 Nirav Prabtani 268
3 Sergey Alexandrovich Kryukov 211
4 CHill60 150
0 OriginalGriff 7,889
1 Sergey Alexandrovich Kryukov 7,006
2 Maciej Los 4,014
3 Peter Leow 3,708
4 CHill60 2,762


Advertise | Privacy | Mobile
Web04 | 2.8.140721.1 | Last Updated 28 Nov 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100