1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
|
#include <iostream>
using namespace std;
//function prototypes
int splitOdd(int[], int[], int);
int splitEven(int[], int[], int);
void displayArr(int[], int);
int main()
{
const int SIZE = 20;
int usedEven, usedOdd;
int origArr[SIZE] = { 4, 7, 12, 6, 8, 3, 30, 7, 20, 13, 17, 6, 31, 4, 3, 19, 15, 9, 12, 18 };
int evenArray[SIZE];
int oddArray[SIZE];
usedEven = splitEven(origArr, evenArray, SIZE);
usedOdd = splitOdd(origArr, oddArray, SIZE);
cout << "Even Values: " << endl;
displayArr(evenArray, usedEven);
cout << endl;
cout << "Odd Values: " << endl;
displayArr(oddArray, usedOdd);
system("pause");
return 0;
}
int splitEven(int origArr[], int evenArray[], int SIZE)
{
int j = 0;
for (int i = 0; i < SIZE; i++ && j++)
{
if (origArr[i] % 2 == 0)
evenArray[j] = origArr[i];
}
return j;
}
int splitOdd(int origArr[], int oddArray[], int SIZE)
{
int k = 0;
for (int i = 0; i < SIZE; i++ && k++)
{
if (origArr[i] % 2 == 1)
oddArray[k] = origArr[i];
}
return k;
}
void displayArr(int newArray[], int used)
{
for (int i = 0; i < used; i++)
cout << newArray[i] << endl;
return;
}
|