I have a character array that array have 10 values .I want the alternate character like 1st,3rd,5th..... from that array .Please any one tell me how to do that
4 Answers
This feels like homework, so I'm not going to give you the solution.
I am going to tell you this:
x % y is the modulo operation. It says "If I divide X by Y, what would the integer remainder be?"
Now, if you were to take this knowledge, and the knowledge that when numbers are EVEN numbers their n % 2 == 0, and ODD numbers n % 2 == 1, can you think of a way, inside a loop, to do this?
With this in mind, edit your question to put the code you've attempted (And, don't just copy one of the other answers and put it as yours.)
Solving these problems for CS majors is like weight-lifting for professional athletes. If you just marked down on the sheet what exercises you did, your coach would probably kick you in the jaw, because you can't perform if you don't exercise. These are your exercise!! :)
Comments
for (int i = 1; i < array.Length; i+=2){
....
}
1 Comment
array[0] and not array[1]