DSA- Print extreme ends of an array

Kapil Patel
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--;
}

--

--

Kapil Patel

Software engineer | loves working in a startup like environment