// 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
new array[] = {7, 2, 5, 1, 3, 8, 6, 3, 4, 6}, count, temp;
for(new i = 0; i < sizeof(array); i ++)
{
if(array[i] % 2)
{
temp = array[count];
array[count ++] = array[i];
array[i] = temp;
}
}
for(new i = 0; i < sizeof(array); i ++)
{
printf("%d", array[i]);
}
pawn Код:
5 (odd) 1 (odd) 3 (odd) 3 (odd) 8 6 2 4 6 What's the task for, if I may ask? |
pawn Код:
5 (odd) 1 (odd) 3 (odd) 3 (odd) 8 6 2 4 6 What's the task for, if I may ask? |
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]). |