de wa nai
1
Q:

c++ reverse array

int arr[5] = {1, 2, 3, 4, 5}; //Initialize array

for(int i = 0; i < size(arr); i++) {
	//Create temporary variable to hold current value in array
	int temp = arr[i];
	//Set the current value in the array to the mirrored value in array
	arr[i] = arr[size(arr) - 1 - i];
	//Set mirrored value in array to temp, swapping the two numbers
	arr[size(arr) - 1 - i] = temp;
}
2

New to Communities?

Join the community