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

List of all available Websheets


Viewing cpp/arrays/fibonacci 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>Write code to compute the first 20 terms of the Fibonacci sequence and store them in an array.</p>
<p>The Fibonacci sequence is defined by the relation: <tt>fib(k) = fib(k-1) + fib(k-2)</tt><br> and <tt>fib(0) = fib(1) = 1</tt>.</p>
<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>
Remarks
Comments, history, license, etc.
 
Copied from problem cpp/arrays/reverse (author: redekopp@usc.edu)
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() {
   int fib[20]; // array to store the first 20 Fibonacci numbers
   
   // generate the Fibonacci sequence
\[
REDACTED
]\
   // output to check it
   for (int i = 0; i < 20; i++){
      cout << fib[i] << " ";
   }
   cout << 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": ""}
]


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