004-004-011
Reversing Array Element Assignment
Medium
Problem Description
Reversing Array Element Assignment
In this problem, you will create a program that reads an array size and elements from standard input, copies the elements into a new array in reverse order, and displays both the original and reversed arrays to standard output.
Learning Objective: Apply array index manipulation to reverse element order
Overview
Create a program that reads an array from input, copies its elements in reverse order into a new array, and prints both.
Input Format
N
a1 a2 ... aN
- Line 1: array size
N(1 ≤ N ≤ 10) - Line 2:
Nspace-separated integers
Specifications
- Use
Scannerto read array sizeN - Read
Nintegers into anint[]array - Create a new array of the same size
- Copy elements in reverse order into the new array
- Print both the original and reversed arrays
Output Format
Original: a1 a2 ... aN
Reversed: aN ... a2 a1
Ready to Try Running Code?
Log in to access the code editor and execute your solutions for this problem.
Don't have an account?
Sign Up