1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
|
#include <iostream>
using namespace std;
void reverse(int[], int);
int main() {
int count;
int Myarr[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
int arrReverse[] = { 10, 9, 8, 7, 6, 5, 4, 3, 2, 1 };
int arrLength = 10;
reverse(Myarr, arrLength);
for (int i = 0; i < arrLength; i++)
if (Myarr[i] == arrReverse[i])
count++;
if (count < arrLength)
cout << "Error: Array not reversed\n" << endl;
else
cout << "Array reversed!" << endl;
return 0;
}
void reverse(int arr[], int length) {
int temp, i;
for (i = 0; i < length / 2; ++i) {
temp = arr[length - i - 1];
arr[length - i - 1] = arr[i];
arr[i] = temp;
}
for (i = 0; i < length; ++i) {
cout << arr[i] << " ";
}
}
|