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