1. ## help with array

Greetings fellow programmers,

I am having difficulty in making a function that checks an integer array for the number '3' and whichever number contains it, moves it to a new array and makes it in descending order.

I am stuck with the moving part and here is what I have done so far:

Code:
```void check(int x[], char y[], int z[]){

int i, j = 0;
char c = 3;
for (i = 0; i < MAX; i++)
y[i]=x[i];
for (i = 0; i < MAX; i++)
while (y[i] != NULL)
{
if (y[i] == c)
{
z[j] = y[i];
j++;
}
}
for (i = 0; i < j; i++)
printf("array2[%d]=%d\n", i, z[i]);
}```
I have a feeling that I am far away from making it works  2. Huh...

If I think I understand what you're saying, you want to search an array for the number 3. If it is found, the index of the array will be stored. The stored indexes will be sorted.

I think that's what you're saying. In which case...
Code:
```const int data = { 3, 0, 3, 1 };

size_t indexes =  { 0 };
size_t num_indexes;

for (size_t i = 0; i < data; ++i) {
if (data[i] == 3) {
indexes[num_indexes] = i;
++num_indexes;
}
}

// sort indexes``` 3. Thanks for the prompt reply.

I need any number that contain '3' to be stored i.e. 13, 2223, 39 etc. not only 3. 4. Originally Posted by ghost00359
I need any number that contain '3' to be stored i.e. 13, 2223, 39 etc. not only 3.
I suggest that you start by writing a function:
Code:
`int has_digit(int number, int digit);`
has_digit will return 1 if number has the given digit, otherwise it will return 0. For example has_digit(2223, 3) == 1, but has_digit(4445) == 0.

Once you have implemented this function and tested that it works correctly, you will find it much easier to accomplish the task of moving the relevant numbers to a new array. 5. Wow thank you very much Popular pages Recent additions 