## tdabboud 3 years ago how can i rearrange an array so all the even numbers will have indices less than those for the odd numbers. This is in C. I have code for the rest of the program

1. Tomas.A

does order matters?

2. tdabboud

no order does not matter

3. tdabboud

void rearrange(int a[]) {int i, b[SIZE]; for(i=0;i<SIZE;i++) {if(a[i]%2) {THEN ITS ODD}

4. tdabboud

thats what i have so far

5. Tomas.A

you can create new array and check old array if it's even and put those numbers there :D and later put odd numbers

6. tdabboud

I am not sure if i know how to do that but i can try. if(a[i]%2) {b[i] = a[i];} //store odd values into new array else{} //I am not sure what to do with it if its even then. make another array?

7. Tomas.A

no you need to index from 0, not to same position

8. Tomas.A

and then increment when you add number http://pastebin.com/F8HT8rmT

9. tdabboud

oh!!! okay that makes sense now. thanks for the help thomas, i appreciate it

10. Tomas.A

i think it's bad solution but it works :D

11. tdabboud

ha I am sure there are other ways to do it but hey it works for me!

12. rsmith6559

You could sort the numbers by their modulus value: qsort( number % 2 ); Something like that.