Difficulty level: Silver
1842 Recursive first time
Title Description Description
Students often encounter this function when they do a problem.
F (x) =5 (x>=0)
F (x) =f (x+1) +f (x+2) +1 (x<0)
Let's do a recursive procedure with this function as a question.
Enter a description input Description
A number represents the X value in F (x)
Everybody notice just one number, the front represents the sample number
outputs description output Description
A number represents a value
Everybody notice just one number, the front represents the sample number
sample input to sample
Example one: 0
Sample two:-5
Sample output Sample outputs
Example one: 5
Sample two: 77
data size & Hint
X>=-30
#include <iostream>usingnamespace std; int f (int x) { if(x>=0return5; return F (x+1) +f (x+2) +1;} int Main () { int x; CIN>>x; cout<<f (x);}
codevs1842 recursion for the first time