Arrays task
#5

1. Loops through all values in the array
2. If value is odd, it saves the value of array with index 0 to 5 (starts at 0, goes up each time an odd number is found) in temp, sets the value of array with the same index to the value of array with the odd number, sets the array that used to have the odd number to temp (which was the value of array with index 0 to 5)

TC;TU

7, 2, 5, 1, 3, 8, 6, 3, 4, 6

becomes

7, 2, 5, 1, 3, 8, 6, 3, 4, 6

Index: 0

-----

7, 2, 5, 1, 3, 8, 6, 3, 4, 6

becomes

7, 5, 2, 1, 3, 8, 6, 3, 4, 6

Index: 1

-----

7, 5, 2, 1, 3, 8, 6, 3, 4, 6

becomes

7, 5, 1, 2, 3, 8, 6, 3, 4, 6

Index: 2

-----

7, 5, 1, 2, 3, 8, 6, 3, 4, 6

becomes

7, 5, 1, 3, 2, 8, 6, 3, 4, 6

Index: 3

-----

7, 5, 1, 3, 2, 8, 6, 3, 4, 6

becomes

7, 5, 1, 3, 3, 8, 6, 2, 4, 6

Index: 4

-----

Still TC;TU

It shifts values (e.g. array[2] = array[5] ; array[5] = array[2]).
Reply


Messages In This Thread
Arrays task - by NeXoR - 29.09.2016, 20:02
Re: Arrays task - by SickAttack - 29.09.2016, 20:18
Re: Arrays task - by NeXoR - 29.09.2016, 20:29
Re: Arrays task - by NeXoR - 29.09.2016, 20:31
Re: Arrays task - by SickAttack - 29.09.2016, 20:58
Re: Arrays task - by NeXoR - 30.09.2016, 04:56

Forum Jump:


Users browsing this thread: 1 Guest(s)