howto make a function read from array A, but put select parts in array B?
im trying to read in 1 array and get 2 as outputs from 3 different functions.
my read array is easy enough were im getting confused is how to read that array, separate it and take out only the parts i want and place them into a 2nd, then again a 3rd array.
i have the following so far:
Code:
#include<stdlib.h>#include<stdio.h>
#include<unistd.h>
#define SIZE 10
void Input_Array(int A[], int size);
void Even_Array(int B[], int size);
void Odd_Array(int C[], int size);
int main(void)
{
int A[SIZE], B[SIZE], C[SIZE], size = SIZE;
Input_Array (A, SIZE);
Even_Array (B, SIZE);
Odd_Array (C, SIZE);
return(0);
}
// code to gather input from user for the 10 elements in the array
void Input_Array(int A[], int size)
{
int i;
printf("Please enter %d integer numbers separated by spaces:\n", size);
for (i = 0; i < size; i++)
scanf("%d", &A[i]);
}
void Even_Array(int B[], int size)
{
int i, A[SIZE];
for (i = 0; i < size; i++)
{
if(A[i]%2 == 0)
{
scanf("%d", &B[i]);
}
}
printf("The Even number Array is as follows: \n");
for (i = 0; i < size; i++)
{
printf("%d\t", B[i]);
}
}
void Odd_Array(int C[], int size)
{
int i, A[SIZE];
for (i = 0; i < size; i++)
{
if(A[i]%2 != 0)
{
scanf("%d", &C[i]);
}
}
printf("The Even number Array is as follows: \n");
for (i = 0; i < size; i++)
{
printf("%d\t", C[i]);
}
}
this compiles without a complaint, but when i go to run it no longer responds after taking the 10th element (well 9th if counting from 0).
I think i have the if correct for the even odd section, but when i try to populate B or C array with the output of that if statement from A is were i think things are dying...
some guidance would be great.
Thank you.