I want to make a new array which contains some of elements from the first array which are greater than 5. (n is the size of the first array)
for (i = 1; i <= n; i++)
{
if (numbers[i] > 5)
{
new_array[i] = numbers[i];
printf("%d ", new_array[i]);
}
}
If I do it like this it works perfectly and prints a new array with only those elements that are greater than 5. But if I write it like this:
for (i = 1; i <= n; i++)
{
if (numbers[i] > 5)
{
new_array[i] = numbers[i];
}
}
for (i = 1; i <= n; i++)
{
printf("%d ", new_array[i]);
}
It doesn't work. It prints an array of n numbers and on the locations where >5 numbers were in the original array there are these numbers but on other locations there are weird numbers. How can I fix this? I want to find the minimum number in the new array and print it.