Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Hi I need help in writing the recursive functions for the following in C, please write a main() that test the functions mentioned below. Thank

Hi I need help in writing the recursive functions for the following in C, please write a main() that test the functions mentioned below. Thank you so much:

Example:

int summ(int n) returns the summation of integers from 0 to n. Here is the code.

int summ(int n) { if(n < 0) return -1; if(n == 0) return 0; return n + summ(n - 1); }

1)

a)int bunnyEars(int n) returns -1 if n is less than 0, otherwise returns the number of ears for n bunnies.

b) int factorial(int n) returns -1 if n is less than 0, otherwise returns the factorial of n c) int fib(int n) returns -1 if n is less than 0, returns 0 if n is 0, returns 1 if n is 1, otherwise returns fib of n - 1 plus fib of n - 2. (If you test this with numbers greater than about 50, it will be very slow.)

d) int posPow(int base, int exp) returns -1 if exp is less than 0, otherwise returns base raised to the power exp.

e) int numDigits(int n) returns the number of digits in n. Hint: in C, as in Java, int division returns an int; any digits that would be after the decimal point are lost, so that, for example, 5/4 is 1.

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

The Temple Of Django Database Performance

Authors: Andrew Brookins

1st Edition

1734303700, 978-1734303704

More Books

Students also viewed these Databases questions