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.
.
.
Click on the title for the 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;
}
}
.
Click on the title for the solution
.
.
This is the answer:
:
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;
}
}
Comments
Post a Comment