0% found this document useful (0 votes)
14 views1 page

Recursion Worksheet for A+ Computer Science

The document is a worksheet focused on recursion in computer science, providing functions that calculate values based on recursive calls. It includes specific functions 'fun', 'go', and 'fly' with their respective logic and conditions. Additionally, it contains runner code that prints the output of these functions for various input values.

Uploaded by

zaidcalls
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views1 page

Recursion Worksheet for A+ Computer Science

The document is a worksheet focused on recursion in computer science, providing functions that calculate values based on recursive calls. It includes specific functions 'fun', 'go', and 'fly' with their respective logic and conditions. Additionally, it contains runner code that prints the output of these functions for various input values.

Uploaded by

zaidcalls
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd

A+ Computer Science – Recursion Worksheet 3

DIRECTIONS : Fill in each blank with the correct answer/output. Assume each
statement happens in order and that one statement may affect the next statement.
Some sections might print more than once.

public static int fun(int x)


{
if(x<1)
return 1;
else
return x+fun(x-1)+fun(x-2);
}

public static int go(int x)


{
if(x<1)
return 1;
else
return x+go(x-2)+go(x-3);
}

public static int fly(int x)


{
if(x<1)
return 1;
else
return x+fly(x-4)+fly(x-1);
}

///////////////////////////////////
//runner code in the main of another class

[Link]("#1 - "+fun(2));

[Link]("#2 - "+fun(6));

[Link]("#3 - "+go(5));

[Link]("#4 - "+go(3));

[Link]("#5 - "+fly(4));

[Link]("#6 - "+fly(5));

© A+ Computer Science – Worksheet – [Link]

You might also like