a.write a program to store the elements in 1-d array and perform the reverse array operation
#include <iostream>
int main() {
int arr[50], size, i, j, temp;
std::cout << "Enter array size: ";
std::cin >> size;
if (size > 50) {
std::cout << "Array size should be less than or equal to 50." << std::endl;
return 1; // Exit with an error code
}
std::cout << "Enter array elements: ";
for (i = 0; i < size; i++) {
std::cin >> arr[i];
}
j = size - 1;
i = 0;
while (i < j) {
temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
i++;
j--;
}
std::cout << "Now the reverse of the array is:\n";
for (i = 0; i < size; i++) {
std::cout << arr[i] << " ";
}
return 0; // Exit successfully
}
No comments