Write C++ program to find reverse of an array


I have used CodeBlocks compiler for debugging purpose. But you can use any C++ programming language compiler as per your availability.


techstudy.org

HP 15 Core i3 7th gen Laptop(4GB, 1TB HDD, Windows 10) | Rs. 31,490

Introduction

I have used CodeBlocks compiler for debugging purpose. But you can use any C++ programming language compiler as per your availability.


  1. #include <iostream>
  2. #define MAX_SIZE 100 //Maximum size of the array
  3. using namespace std;
  4.  
  5. int main() {
  6. int array[MAX_SIZE];
  7. int size, i;
  8.  
  9. // Reading size of array
  10. cout<<"Enter size of the array: ";
  11. cin>>size;
  12.  
  13. // Reading array elements
  14. cout<<"Enter elements in array: ";
  15. for (i = 0; i < size; i++) {
  16. cin>>array[i];
  17. }
  18.  
  19. //Print array in reversed order
  20. cout<<"\nArray in reverse order: ";
  21. for (i = size - 1; i >= 0; i--) {
  22. cout<<"\t"<< array[i];
  23. }
  24.  
  25. return 0;
  26. }

Result

C++ language techstudy.org

     





Related Topics




Popular Posts