Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

Ask Engineering Mathematics Expert

Objective

Learn to pass parameters and write a simple recursive subroutine.

Background

In the previous lab, you were required to write a program to accept a positive integer value N, use a subroutine to compute Y where

676_positive integer value.jpg

and print the result on the screen. Let's rewrite this as

Y (M, N) = Y(M) + Y(N)

where

2144_program to accept a positive integer value.jpg

The same problem can be solved recursively. To do that, let's define this function Y(P) as follows:

1. Y(1) = 1. This is the base case.

2. Y(P) = P + Y(P-1).

Notice that Y(P) is defined in terms of a simpler version of itself.

For example, let's say we wish to compute Y(4). The steps would then be

Y(4) = 4 + Y(3) we need to find Y(3) before we can finish computing Y(4)
Y(4) = 4 + (3 + Y(2)) now we need to find Y(2)
Y(4) = (3 + (2 + Y(1))) and now we need Y(1)
Y(4) = 4 + (3 + (2 + 1)) but Y(1) is 1 from our base case
Y(4) = 4 + (3 + 3) evaluate and finish
Y(4) = 4 + 6
Y(4) = 10

Engineering Mathematics, Engineering

  • Category:- Engineering Mathematics
  • Reference No.:- M91526095
  • Price:- $30

Priced at Now at $30, Verified Solution

Have any Question?


Related Questions in Engineering Mathematics

Show all your work not just the answerswhen you multiply 21

(SHOW ALL YOUR WORK, not just the answers) When you multiply: 21 x 68 you most likely do: 8x1 + 8x20 + 60x1 + 60x20 = 1, 428 So, there are 4 multiplications and then 3 additions. How long would it take a computer to do t ...

Question what is the signed binary sum of 1011100 and

Question : What is the signed binary sum of 1011100 and 1110101 in decimal? Show all of your work. What is the hexadecimal sum of 9A88 and 4AF6 in hexadecimal and decimal? Show all of your work.

Assignment - introduction to math programmingdirections

Assignment - Introduction to Math Programming Directions - Formulate a linear programming model for the following description. Include definitions of decision variables, Objective function, and constraints. Augment your ...

1 this problem concerns of the proof of the np-completeness

(1) This problem concerns of the proof of the NP-completeness of 300L a) Convert the formula F into a 300L graph b) Find a solution for the 300L instance of F and verify that it is a solution for F F = (Z 1 V Z 2 ) ^ (z ...

Question 1 - many spas many componentsconsider 4 types of

Question 1 - Many spas, many components Consider 4 types of spa tub: Aqua-Spa (or FirstSpa, or P1), Hydro-Lux (or SecondSpa, or P2), ThirdSpa (or P3) and FourthSpa (or P4), with the production of products P1, ..., P4 in ...

I have these questions for a homework assignment and have

I have these questions for a homework assignment and have to show work. This works with MIPS coding language and is the class Introduction to Computer Architecture. 1. Find the 2's complement representation (in 32-bit he ...

Assignment -1 let t and or 0 1 be a boolean algebradefine

Assignment - 1. Let (T, ∧, ∨,', 0, 1) be a Boolean Algebra. Define ∗ : T × T → T and o : T × T → T as follows: x ∗ y := (x ∨ y)' x o y := (x ∧ y)' (a) Show, using the laws of Boolean Algebra, how to define x ∗ y using on ...

All these questions should be answered in matlab 1 generate

All these questions should be answered in MATLAB !!! 1. Generate a set of 3 random patterns of dimension 12 where each value is +1 or -1.(3 random 12*12 matrix) 2. Create a 12-unit Hopfield network (a 12x12 matrix) from ...

Question a suppose that you are given an instance of the

Question : (a) Suppose that you are given an instance of the MST problem on a graph G, with edge weights that are all positive and distinct. Let T be the minimum spanning tree for G returned by Kruskal's algorithm. Now s ...

Question suppose that g is a directed graph in class we

Question : Suppose that G is a directed graph. In class we discussed an algorithm that will determine whether a given vertex can reach every other vertex in the graph (this is the 1-to-many reachability problem). Conside ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As