fork download
  1. //Cecilia Rangel CSC5 Chapter 9, P.539, #10
  2. //
  3. /**************************************************************
  4.  *
  5.  * REVERSE SHIFT ELEMENT ARRAY
  6.  * ____________________________________________________________
  7.  * This program creates an array of intergers, then creates a
  8.  * shifted array of elements that flips the order of elements
  9.  *
  10.  *_____________________________________________________________
  11.  *
  12.  * OUTPUT
  13.  * Array : OUTPUT a array shifted once
  14.  * to the right
  15.  * ***************************************************************/
  16. #include <iostream>
  17. #include <iomanip>
  18. using namespace std;
  19.  
  20. void reverseArray(int array[], int i);
  21.  
  22. const int SIZE = 5;
  23. int main()
  24. {
  25. int i;
  26. int array[SIZE] = {1, 2, 3, 4, 5};
  27.  
  28.  
  29. cout << "Current array :" << endl;
  30. for(i=0; i< SIZE; i++)
  31. {
  32. cout << array[i];
  33. }
  34. cout << endl << "Array in reverse: " << endl;
  35. reverseArray(array, i);
  36. return 0;
  37. }
  38. /***************************************************************************
  39.  * reverseArray
  40.  * ________________________________________________________________________
  41.  * The function should take array from main and then
  42.  * reverse the elements in the array and display the array in reverse.
  43.  *
  44.  * ************************************************************************/
  45. void reverseArray(int array[] ,int i)
  46. {
  47. for(i= (SIZE-1); i >=0; i--)
  48. {
  49. cout << array[i];
  50. }
  51. }
Success #stdin #stdout 0s 5344KB
stdin
Standard input is empty
stdout
Current array :
12345
Array in reverse: 
54321