Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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

Advances In Database Technology Edbt 88 International Conference On Extending Database Technology Venice Italy March 14 18 1988 Proceedings Lncs 303

Authors: Joachim W. Schmidt ,Stefano Ceri ,Michele Missikoff

1988th Edition

3540190740, 978-3540190745

More Books

Students also viewed these Databases questions