top of page

Reverse an array in same array.

  • Writer: prashant raj
    prashant raj
  • Apr 21, 2022
  • 1 min read


#include <iostream>

using namespace std;

int main()
{
    int arr[] = {1,2,3,4,5,6,7};
    
    int len = sizeof(arr)/sizeof(arr[0]);
    
    for(int i = 0; i < len/2; i++)
    {
        int j = len - i -1;
        
        int tmp = arr[i];
        arr[i] = arr[j];
        arr[j] = tmp;
    }
    for(int i = 0;i<len;i++)
    {
        cout<<arr[i];
    }
    cout<<endl;

    return 0;
}

Comments


Drop Me a Line, Let Me Know What You Think

Thanks for submitting!

© 2023 by Train of Thoughts. Proudly created with Wix.com

bottom of page