29.09.2016, 20:02
Hello guys, I have been given some tasks to do, and I need help with the final task
Alright here's an explanation for the task:
I have a 10 cells array called Arr, and it contains the numbers
7,2,5,1,3,8,6,3,4,6
Now I have to transfer the dual numbers to the right side of the array (Arr[5-10])
and the odd numbers to the left side.
Thats the code:
And thats the print:
Anyone help ?
Alright here's an explanation for the task:
I have a 10 cells array called Arr, and it contains the numbers
7,2,5,1,3,8,6,3,4,6
Now I have to transfer the dual numbers to the right side of the array (Arr[5-10])
and the odd numbers to the left side.
Thats the code:
PHP код:
// Task 4
for(new i = 5; i < 10; i++)
{
for(new j = 0; j < sizeof(Arr); j++)
{
if(Arr[j] % 2 == 0 && Arr[i] != Arr[j]) Arr[i] = Arr[j];
}
}
for(new i = 0; i < 5; i++)
{
for(new j = 0; j < sizeof(Arr); j++)
{
if(Arr[j] % 2 != 0 && Arr[i] != Arr[j]) Arr[i] = Arr[j];
}
}
for(new k = 0; k < sizeof(Arr); k++) printf("Arr[%i] = %d", k, Arr[k]);
Код:
[22:50:36] Arr[0] = 3 [22:50:36] Arr[1] = 3 [22:50:36] Arr[2] = 3 [22:50:36] Arr[3] = 3 [22:50:36] Arr[4] = 3 [22:50:36] Arr[5] = 6 [22:50:36] Arr[6] = 6 [22:50:36] Arr[7] = 6 [22:50:36] Arr[8] = 6 [22:50:36] Arr[9] = 6