Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

1. The famous Fibonacci sequence f1,52, f3,... is defined as f1 = 1, f2 = 1 fn = fn-1 + fn-2, for n > 2

image text in transcribedimage text in transcribed

1. The famous Fibonacci sequence f1,52, f3,... is defined as f1 = 1, f2 = 1 fn = fn-1 + fn-2, for n > 2 So the sequence begins as 1,1,2,3,5,8,13,21,34, .... Define a recursive function int fibonacci(int n) which returns the n-th Fibonacci number. 2. Define recursive function my_sequence(n) which returns the n-th member of the se- quence a1 = 3, a2 = 5, a3 = -7, an = An-1 - 2an-2 + an-3, n > 3. 3. Define recursive function sum(n) which returns 1+2+3+...+n. 4. Define recursive function sum_squares (n) which returns 12 + 22 + 32 + ... + n2. 5. Define a recursive function double my-pow(double a, int n) which returns an for integers n > 0. Do not use library . 6. It is not difficult to show that n 1 1 1 1 1 n n +1 i(i + 2+7+7+...+ n(n + 1) So a simple C++ function which computes this sum is double f(int n) {return 1.0*n/(n+1); } Define a recursive function which computes this sum directly, without using the for- mula. 7. Define recursive function void print_digits_reverse(unsigned int) which takes an unsigned int as input and prints its digits in reverse on the console (cout). (Hint: n/10 is the same as n with its ones digit removed.) 8. Define recursive function print_many_3s(n) which prints n threes to the console. 9. Define recursive function print_rectangle(m,n) which prints an mxn grid of *'s. For example, print_rectangle(4,3) yields *** * * * *** *** 10. Define function sequence(m,n) which prints the sequence of integers from m to n, counting up if m n. For example, sequence(-1,3) prints -1 am while sequence(5,2) yields LM<>

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

What is total cost?

Answered: 1 week ago