reverse an array in c 2b 2b using while loop

Solutions on MaxInterview for reverse an array in c 2b 2b using while loop by the best coders in the world

showing results for - "reverse an array in c 2b 2b using while loop"
Timothée
17 Apr 2017
1#include <iostream>
2using namespace std;
3int main()
4{
5	const int SIZE = 9;
6	int arr [SIZE];
7	cout << "Enter numbers: \n";
8	for (int i = 0; i < SIZE; i++)
9		cin >> arr[i];
10	for (int i = 0; i < SIZE; i++)
11		cout << arr[i] << "\t";
12	cout << endl;
13	cout << "Reversed Array:\n";
14	int temp, start = 0, end = SIZE-1;
15	while (start < end)
16	{
17		temp = arr[start];
18		arr[start] = arr[end];
19		arr[end] = temp;
20		start++;
21		end--;
22	}
23	for (int i = 0; i < SIZE; i++)
24		cout << arr[i] << "\t";
25	cout << endl;	
26	}
27