DSA- Print extreme ends of an array
May 20, 2023
Given an array int arr[] = {10, 20, 30, 66, 5};
Output: 10 5 20 66 30
int arr[] = {10, 20, 30, 50, 99, 5, 11, 13, 66,5};
int start = 0;
int arrLength = sizeof(arr) / sizeof(int);
int end = arrLength - 1;
while (start <= end) {
if (start == end) {
cout << arr[start] << " ";
} else {
cout << arr[start] << " ";
cout << arr[end] << " ";
}
start++;
end--;
}