fork download
// Hudson price			 CS1A				   

/*******************************************************************************
 * Shift Elements in Array
 *______________________________________________________________________________
 *this program will duplicate the array nd shit it by one 
 *  The function will return the pointer of the new array.
 *______________________________________________________________________________
 * INPUT
 * the arrayof origional pointers
 * 
 * OUTPUT
 * poibnter with tthe shifted elements
 * 
 ******************************************************************************/
 #include <iostream>

using namespace std;

int* expandArray(const int* arr, int size);

int main() 
{
    
    int arr[] = {1, 2, 3, 4, 5};
    int size = sizeof(arr) / sizeof(arr[0]);

    int* expandedArr = expandArray(arr, size);

    cout << "Expanded array:\n";
    for (int i = 0; i < 2 * size; ++i) 
    {
        cout << expandedArr[i] << " ";
    }
    cout << endl;

   
    delete[] expandedArr;

    return 0;
}

int* expandArray(const int* arr, int size) 
{
 
    int* newArr = new int[2 * size];

       for (int i = 0; i < size; ++i) 
    {
        newArr[i] = arr[i];
    }

    for (int i = size; i < 2 * size; ++i) 
    {
        newArr[i] = 0;
    }

    return newArr;
}
Success #stdin #stdout 0s 5304KB
stdin
Standard input is empty
stdout
Expanded array:
1 2 3 4 5 0 0 0 0 0