Question: Simple C# Questions. Cannot use LINX Write a console application to accomplish the following tasks. The methods you write should return the results to the

Simple C# Questions.

Cannot use LINX

Write a console application to accomplish the following tasks. The methods you write should return the results to the client(main) and main should print the results with approprate labels. Use /// comments on all of your methods other than main.

1) Write a method that when given a non-negative int n, finds the sum of the digits recursively and returns the sum for the client to print. NO LOOPS. ex. 126 = 9, recall that mod (%) by 10 yields the rightmost digit (126 % 10 is 6), while divide (/) by 10 removes the rightmost digit (126 / 10 is 12).

2) Write a method that when given base and n that are both integers greater than or equal to 1, compute recursively (no loops) the value of base to the n power, so powerN(3, 2) is 9 (3 squared).

3) We have triangle made of blocks. The topmost row has 1 block, the next row down has 2 blocks, the next row has 3 blocks, and so on. Write a method that when given the number of rows, recursively computes (no loops or multiplication) the total number of blocks in such a triangle.

4) The Fibonacci sequence is a famous bit of mathematics, and it happens to have a recursive definition. The first two values in the sequence are 0 and 1 (essentially 2 base cases). Each subsequent value is the sum of the previous two values, so the whole sequence is: 0, 1, 1, 2, 3, 5, 8, 13, 21 and so on. Write a recursive method, Fibonacci(n), that returns the nth Fibonacci number, with n=0 representing the start of the sequence.

5) Write a non-recursive solution to Fibonacci using the same sequence and value. Answer the following: Which is more efficient and why?

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!