Arrays task
#1

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:
PHP код:
// Task 4
    
for(new 510i++)
    {
        for(new 
0sizeof(Arr); j++)
        {
            if(
Arr[j] % == && Arr[i] != Arr[j]) Arr[i] = Arr[j];
        }
    }
    for(new 
05i++)
    {
        for(new 
0sizeof(Arr); j++)
        {
            if(
Arr[j] % != && Arr[i] != Arr[j]) Arr[i] = Arr[j];
        }
    }
    for(new 
0sizeof(Arr); k++) printf("Arr[%i] = %d"kArr[k]); 
And thats the print:
Код:
[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
Anyone help ?
Reply
#2

pawn Код:
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]);
}
7 (odd)
5 (odd)
1 (odd)
3 (odd)
3 (odd)
8
6
2
4
6

What's the task for, if I may ask?
Reply
#3

Quote:
Originally Posted by SickAttack
Посмотреть сообщение
pawn Код:
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]);
}
7 (odd)
5 (odd)
1 (odd)
3 (odd)
3 (odd)
8
6
2
4
6

What's the task for, if I may ask?
I want to be a scripter in a server I like to play in, and it's some sort of a test that the programmer gave me to be an assistant scripter.
Thanks for the help.
Reply
#4

Quote:
Originally Posted by SickAttack
Посмотреть сообщение
pawn Код:
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]);
}
7 (odd)
5 (odd)
1 (odd)
3 (odd)
3 (odd)
8
6
2
4
6

What's the task for, if I may ask?
Sorry for double posting, can I get a small explanation of the process ? So I could learn to the future
Reply
#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
#6

Quote:
Originally Posted by SickAttack
Посмотреть сообщение
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]).
Thank you very much
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)