In: Computer Science
In C++. Thank you!
C++ CODE:
#include <iostream> #include <cstdlib> #include <ctime> using namespace std; int main(){ int arr[100];//Create 100 elements array srand(time(NULL));//Seeds for rand() //Fill random numbers in arr for(int i = 0; i < 100; i++) arr[i] = rand() % 100 + 1;//Fill with random numbers between 1 and 100 int oddArr[100], evenArr[100];//Create two 100-elements array int oddArrSize = 0, evenArrSize = 0; for(int i = 0; i < 100; i++) if(arr[i] % 2 == 0)//If element is even evenArr[evenArrSize++] = arr[i]; else//Otherwise element is odd oddArr[oddArrSize++] = arr[i]; //Print both odd and even arrays cout << "Odd array: "; for(int i = 0; i < oddArrSize; i++) cout << oddArr[i] << " "; cout << endl << endl; cout << "Even array: "; for(int i = 0; i < evenArrSize; i++) cout << evenArr[i] << " "; cout << endl << endl; return 0; }
SAMPLE OUTPUT: