List of all available Websheets
Viewing cpp/cs103/hw-arrays/fill by daveagp@gmail.com. You have unsaved changes. Log in above to create, edit, preview and publish Websheets.
Property | Value |
---|---|
Description html markup shown to student | This program should take an integer <tt>n</tt> as input, then print out the square roots of the numbers from <tt>0</tt> to <tt>n-1</tt>. <p> The input/output is provided for you. Fill in the loop so that the array <tt>values</tt> contains the desired square roots. <p> Remember that <tt>sqrt(x)</tt> is the function to compute the square root of <tt>x</tt>. |
Engine | |
Template / Reference solution |
using namespace std; int main() { // read the input int n; cin >> n; double values[100]; // declare an array, max size 100 for (int i = 0; i < n; i++) { // element i of the array should contain the square root of i \[ REDACTED ]\ } for (int i = 0; i < n; i++) { cout << "The square root of " << i << " is " << values[i] << endl; } 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": "5"}, {"stdin": "20"}, {"stdin": "0"} ] |
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'.