We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
void reverse(int arr[], int n) { // Change return type to void
int start = 0;
int end = n - 1;
int temp;
while (start < end) {
temp = arr[start];
arr[start] = arr[end];
arr[end] = temp;
start++;
end--;
}
}
int main() {
int arr[] = {2, 3, 4, 5, 6, 7, 8};
int n = sizeof(arr) / sizeof(arr[0]);
reverse(arr, n); // Call the reverse function
// Print the reversed array
for (int i = 0; i < n; i++) {
cout << arr[i] << " ";
}
cout << endl;
return 0;
}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Arrays - DS
You are viewing a single comment's thread. Return to all comments →
include
using namespace std;
void reverse(int arr[], int n) { // Change return type to void int start = 0; int end = n - 1; int temp; while (start < end) { temp = arr[start]; arr[start] = arr[end]; arr[end] = temp; start++; end--; } }
int main() { int arr[] = {2, 3, 4, 5, 6, 7, 8}; int n = sizeof(arr) / sizeof(arr[0]);
}