id/email
password
forgot password | create account
about | help | code help+videos | done | prefs
CodingBat code practice

 

simona1@sfusd.edu recursion1 > subtractonacci
prev  |  next  |  chance

This variation on the Fibonacci sequence uses subtraction instead of addition. In this sequence the first two numbers are 1 and 2. Each subsequent value is the difference of the previous two values. The third value is 1-2 or -1. The fourth value is 2-(-1) or 3. The first ten numbers in this sequence are 1, 2, -1, 3, -4, 7, -11, 18, -29 and 47. (You can read more about sequences like this at https://oeis.org/A061084)


subtractonacci(0) → 1
subtractonacci(1) → 2
subtractonacci(2) → -1

...Save, Compile, Run (ctrl-enter)

public int subtractonacci(int n){ }

Editor font size %:
Shorter output


Forget It! -- delete my code for this problem

Progress graphs:
 Your progress graph for this problem
 Random user progress graph for this problem
 Random Epic Progress Graph

Java Help

Misc Code Practice

Copyright Nick Parlante 2017 - privacy