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

List of all available Websheets


Viewing cpp/passing/reset_array by daveagp@gmail.com. You have unsaved changes. Log in above to create, edit, preview and publish Websheets.
PropertyValue
Description
html markup
shown to student
 
Define a function <tt>void reset_array(int arr[], int n)</tt> 
that takes an array <tt>arr</tt> of length <tt>n</tt>, 
and resets all of its entries to zero.
<p>You should <b>not</b> use cin or cout, that part is done for you
in order to facilitate testing.
Public permissions remove
Engine
Template / Reference solution
 
#include <iostream>
using namespace std;
void reset_array(int arr[], int n) {
\[
   for (int i=0; i<n; i++)
      arr[i] = 0;
]\
}
int main() {
   int the_inputs[100];
   int n;
   // read n, then n inputs
   cin >> n;
   for (int i=0; i<n; i++) cin >> the_inputs[i];
   // call YOUR function
   reset_array(the_inputs, n);
   // is the output correct?
   cout << "After calling your function, the array contains: ";
   for (int i=0; i<n; i++) cout << the_inputs[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": "3\n2014 9 17"},
   {"stdin": "8\n99 11 17 71 39 0 93 38"}
]
Solution visibility remove


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'.