fork download
  1. //OrinTill Qimid CS1A Chapter 4, P. 294, 10
  2. //
  3. /**************************************************************
  4.  * Element Shift
  5.  *
  6.  * ____________________________________________________________
  7.  * This program will shift the array down one element.
  8.  * ____________________________________________________________
  9.  * INPUT
  10.  * SIZE : array size.
  11.  * OUTPUT
  12.  * arr2 : new array.
  13.  **************************************************************/
  14. #include <iostream>
  15. #include <iomanip>
  16. #include <cmath>
  17. using namespace std;
  18. const int SIZE = 5;
  19. int* element_shift(int arr[], int size)
  20. {
  21. int new_size = size+1 ;
  22. int* arr2 = new int [new_size];
  23. arr2[0]= 0;
  24. for (int i = 0; i <= new_size; i++)
  25. {
  26. arr2[i+1] = arr[i];
  27. }
  28. return arr2;
  29. }
  30. int main()
  31. {
  32. int arr [SIZE] = { 1, 2, 3, 4, 5};
  33.  
  34. int* arr2 = element_shift(arr, SIZE);
  35.  
  36. delete arr2;
  37.  
  38. return 0 ;
  39. }
Success #stdin #stdout 0s 5272KB
stdin
Standard input is empty
stdout
Standard output is empty