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

List of all available Websheets


Viewing cpp/arrays/sumpairs 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
 
<p>Complete the program to output the sum of the: </p>
<ol>
   <li>First and last</li>
   <li>Second and second to last</li>
   <li>Thirs and third to last</li>
   <li>...</li>
</ol>
<p>So if the array is: <tt>9 8 4 5 6 2</tt> your program should output: </p>
<pre>
11
14
9
</pre>
<p><strong>You may assume the size of the array is even.</strong></p>
   
Public permissions remove
Remarks
Comments, history, license, etc.
 
Copied from problem cpp/arrays/arrayprint (author: dpritcha@usc.edu)
remove
Engine
Template / Reference solution
 
#include <iostream>
#include <string>
using namespace std;
int main() 
{
   int n;
   
   // biggest possible
   int arr[20];
   cin >> n;
   
   for(int i=0; i < n; i++){
     cin >> arr[i];  
   }
\[
   for(int i=0; i < n/2; i++)
   {
     cout << arr[i] + arr[n - i -1] << 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":"12 9 15 10 13 6 3 8 1 5 10 13 2", "args":[]},
   {"stdin":"8 10 5 7 3 4 9 6 8", "args":[] }
]
Solution visibility remove
Add compiler flag(s)
json list of flags
e.g. ["-Wno-unused-variable"]
 
["-Wno-array-bounds"]
remove
Remove default compiler flag(s)
json list of flags
see default_cppflags
e.g. ["-Wno-write-strings"]
 
["-fsanitize=undefined"]
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'.