Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /******************************************************************************
- Welcome to GDB Online.
- GDB online is an online compiler and debugger tool for C, C++, Python, Java, PHP, Ruby, Perl,
- C#, VB, Swift, Pascal, Fortran, Haskell, Objective-C, Assembly, HTML, CSS, JS, SQLite, Prolog.
- Code, Compile, Run and Debug online from anywhere in world.
- *******************************************************************************/
- #include<iostream>
- #include<stdlib.h>
- using namespace std;
- //function that will intialize array
- void intialize_array(int arr[],int size)
- {
- for(int i=0;i<size;i++)
- {
- arr[i]=i;
- }
- }
- void print_array(const int arr[],int size)
- {
- cout<<"[";
- for(int i=0;i<size;i++)
- {
- cout<<arr[i]<<",";
- }
- cout<<"]"<<endl;
- }
- int * shuffle_array(const int arr[], int size)
- {
- int *NewArray1 = new int[size];
- for(int i=0; i<size; i++)
- {
- NewArray1[i] = arr[i];
- }
- for(int i=size-1; i>=0; i--) {
- int j = rand() % (i+1);
- int temp = NewArray1[j];
- NewArray1[j] = NewArray1[i];
- NewArray1[i] = temp;
- }
- return NewArray1;
- }
- int *createOddArray(const int arr[], int size, int &oddnum)
- {
- int *OddArray = new int[size],j=0;
- for(int i = 0;i<size;i++)
- {
- if(arr[i] % 2 == 1)
- {
- OddArray[j]=arr[i];
- j++;
- }
- }
- oddnum=j;
- return OddArray;
- }
- int *createEvenArray(const int arr[], int size, int &evennum)
- {
- int *EvenArray = new int[size],j=0;
- for(int i = 0;i<size;i++)
- {
- if(arr[i] % 2 == 0)
- {
- EvenArray[j]=arr[i];
- j++;
- }
- }
- evennum=j;
- return EvenArray;
- }
- int main()
- {
- int arraysize;
- cout<< "What is the size of your array (from 1 to 52)";
- cin>> arraysize;
- while(arraysize <=0 || arraysize > 52)
- {
- cout<< "Select your array size from 1 to 52";
- cin>> arraysize;
- }
- int array1[arraysize];
- intialize_array(array1,arraysize);
- cout<<"The original array is:";
- print_array(array1,arraysize);
- int *shuffled=shuffle_array(array1,arraysize);
- cout<<"The shuffled array is :";
- print_array(shuffled,arraysize);
- int oddnum;
- int *oddnumArray = createOddArray(array1,arraysize,oddnum);
- cout<<"The odd array is:";
- print_array(oddnumArray,oddnum);
- int evennum;
- int *evennumArray = createEvenArray(array1,arraysize,evennum);
- cout<<"The even array is";
- print_array(evennumArray,evennum);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement