Thank you for all of your help. that was fantastic. I LEARNED and I succeeded in creating what I needed:
Code:
#include<stdlib.h>#include<stdio.h>
#include<unistd.h>
#define SIZE 10
void Input_Array(int all_numbers[], int size);
int Even_Array(int even_numbers_only[], int all_numbers[], int size);
int Odd_Array(int odd_numbers_only[], int all_numbers[], int size);
void Print_Even_Array(int even_numbers_only[], int size);
void Print_Odd_Array(int odd_numbers_only[], int size);
int main(void)
{
int all_numbers[SIZE], even_numbers_only[SIZE], odd_numbers_only[SIZE], size = SIZE;
Input_Array(all_numbers, SIZE);
Even_Array(even_numbers_only, all_numbers, SIZE);
Print_Even_Array(even_numbers_only, Even_Array(even_numbers_only, all_numbers, SIZE));
Print_Odd_Array(odd_numbers_only, Odd_Array(odd_numbers_only, all_numbers, SIZE));
return(0);
}
// code to gather input from user for the 10 elements in the array
void Input_Array(int all_numbers[], int size)
{
int i;
printf("Please enter %d integer numbers separated by spaces:\n", size);
for (i = 0; i < size; i++)
scanf("%d", &all_numbers[i]);
}
int Even_Array(int even_numbers_only[], int all_numbers[], int size)
{
int i, j, result_even, *new_size;
j=0;
for (i = 0; i < size; i++)
{
if(all_numbers[i]%2 == 0)
{
even_numbers_only[j] = all_numbers[i];
j++;
}
}
return j;
}
void Print_Even_Array(int even_numbers_only[], int size)
{
int i;
printf("The even numbers are: \n\n");
for (i = 0; i < size; i++)
{
printf("%d\t", even_numbers_only[i]);
}
printf("\nThere are [%d] elements in this array\n\n", i);
}
int Odd_Array(int odd_numbers_only[], int all_numbers[], int size)
{
int i, j;
j=0;
for (i = 0; i < size; i++)
{
if(all_numbers[i]%2 != 0)
{
odd_numbers_only[j] = all_numbers[i];
j++;
}
}
return j;
}
void Print_Odd_Array(int odd_numbers_only[], int size)
{
int i;
printf("The odd numbers are: \n\n");
for (i = 0; i < size; i++)
{
printf("%d\t", odd_numbers_only[i]);
}
printf("\nThere are [%d] elements in this array\n\n", i);
}
with flawless results:
Code:
ssma-imac:ENG-3211 ssma$ ./even_odd
Please enter 10 integer numbers separated by spaces:
1 2 3 4 5 6 7 8 9 0
The even numbers are:
2 4 6 8 0
There are [5] elements in this array
The odd numbers are:
1 3 5 7 9
There are [5] elements in this array
ssma-imac:ENG-3211 ssma$ ./even_odd
Please enter 10 integer numbers separated by spaces:
2 2 2 2 2 2 2 2 2 2
The even numbers are:
2 2 2 2 2 2 2 2 2 2
There are [10] elements in this array
The odd numbers are:
There are [0] elements in this array
ssma-imac:ENG-3211 ssma$ ./even_odd
Please enter 10 integer numbers separated by spaces:
1 1 2 3 5 6 18 2222222 1111111 3
The even numbers are:
2 6 18 2222222
There are [4] elements in this array
The odd numbers are:
1 1 3 5 1111111 3
There are [6] elements in this array
ssma-imac:ENG-3211 ssma$
Thank you again. FYI it was just a wild guess on my part to put the function inside of the function for the size of the print functions... not sure if that is standard, but it seems to be working.
Is there a better way to do that?