Not logged in. Log in with GitHub. About Websheets.

List of all available Websheets


Viewing cpp/arrays/reverse by redekopp@usc.edu. You have unsaved changes. Log in above to create, edit, preview and publish Websheets.
PropertyValue
Description
html markup
shown to student
 
Write a code fragment to reverse the values of an array.  If the array contains
<style>
table.t * {font-family: 'Source Code Pro', monospace !important;}
table.t * {border: 1px solid black !important;}
table.t {border-collapse: collapse; width: auto !important;}
span.spoiler {color: white; border: 1px solid black;}
</style>
<table class='t'><tr><td>4<td>3<td>17<td>1</table>
then your code should modify it to
<table class='t'><tr><td>1<td>17<td>3<td>4</table>
<b>Note:</b> the program will read the array size <tt>n</tt> and <tt>data</tt>
from input. The output is done for you. You just need to reverse the array.
Remarks
Comments, history, license, etc.
 
Copied from problem cpp/cs103/hw-arrays/reverse_copy (author: redekopp@usc.edu)
remove
Engine
Template / Reference solution
 
#include <iostream>
#include <cmath>
using namespace std;
int main() {
   // read the input
   int n;
   cin >> n;
   int data[100]; // declare an array, max size 100
   for (int i = 0; i < n; i++) 
      cin >> data[i]; // read elements of data from input
   // reverse the data arrays
\[
REDACTED
]\
   // output dest to check it
   for (int i = 0; i < n; i++)
      cout << data[i] << " ";
   return 0;
}
C++ test suite
json list of stdin/args tests
e.g. [{"stdin":"hi", "args":["4", "5"]},
{"stdin":"noargs"}]

to just run once with no input use [{}]
 
[
   {"stdin": "4\n1 17 3 4"},
   {"stdin": "5\n90210 2014 103 11 6"},
   {"stdin": "6\n4 8 15 16 23 42"},
   {"stdin": "10\n4 1 6 9 6 7 1 1 1 1"}
]


Optional properties:

Note: problems are open-source by default (see 'Public permissions'). Assumed license for open problems is Creative Commons 4.0 Attribution-ShareAlike unless specified in 'Remarks'.