Write the definition of a function reverse, whose first parameter is an array of integers and whose second parameter is the number of elements in the array. The function reverses the elements of the array. The function does not return a value.

1
Write the definition of a function reverse, whose first parameter is an array of integers and whose second parameter is the number of elements in the array. The function reverses the elements of the array. The function does not return a value.

LANGUAGE: C++

CHALLENGE:

Write the definition of a function reverse, whose first parameter is an array of integers and whose second parameter is the number of elements in the array. The function reverses the elements of the array. The function does not return a value.

SOLUTION:


void reverse (int a[], int n){
    int temp;
    for (int k=0; k<n/2; k++){
        temp=a[k];
        a[k]=a[n-k-1];
        a[n-k-1]=temp;
    }
}

One comment

Add comment