fork download
  1. //OrinTill Qimid CS1A Chapter 4, P. 294, 10
  2. //
  3. /**************************************************************
  4.  * REVERSE ARRAY
  5.  *
  6.  * ____________________________________________________________
  7.  * This program will reverse the firswt array and create a second one.
  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* reverse_arr(int arr[], int size)
  20. {
  21. int* arr2 = new int [size];
  22. int count;
  23. count = 1;
  24. for (int i = 0; i <size; i++)
  25. {
  26. arr2[i] = arr[size - count];
  27. count++;
  28. }
  29.  
  30. return arr2;
  31. }
  32. int main()
  33. {
  34. int arr [SIZE] = { 1, 2, 3, 4, 5};
  35. int* arr2 = reverse_arr(arr, SIZE);
  36. for (int i = 0; i < SIZE; i++)
  37. {
  38. cout << arr2[i]<<endl;
  39. }
  40. delete arr2;
  41.  
  42.  
  43. return 0 ;
  44. }
Success #stdin #stdout 0s 5284KB
stdin
Standard input is empty
stdout
Standard output is empty