Answers for "reverse function in array"

PHP
55

javascript reverse array

var arr = [34, 234, 567, 4];
print(arr);
var new_arr = arr.reverse();
print(new_arr);
Posted by: Guest on November-16-2019
3

reverse array in a new array

#include <iostream>
#include <iomanip>

using namespace std;

void reverseArray(int array[],int newArray[],int size);
void printArray (int array[],int size);

int main()
{
    int list [6],newList[6];
    for(int i=0;i<6;i++){
        cout<<"Element "<<i<<": ";
        cin>>list[i];
    }
    
    reverseArray(list,newList,6);
    cout<<"Original array: \n";
    printArray (list,6);
    cout<<endl<<"Reversed array: \n";
    printArray (newList,6);
    
}

void reverseArray(int array[],int newArray[],int size){
    for(int i=0,j=size-1;i<size;i++,j--)      
        newArray[j]=array[i];
}

void printArray (int array[],int size){
    for(int i=0;i<size;i++)
        cout<<setw(5)<<array[i];
}
Posted by: Guest on April-16-2022

Code answers related to "reverse function in array"

Browse Popular Code Answers by Language