Question

In: Computer Science

Given is a sequence of the following pattern: {1, 2, 6, 24, 120, 720, …} 1....

Given is a sequence of the following pattern: {1, 2, 6, 24, 120, 720, …}

1. Write recursive equations for the above sequence.

2. Write a C++ recursive function that can compute the sequence in 1. above of any
unsigned long number.

Solutions

Expert Solution

The n-th term of the sequence is the product of the first n positive integers.

1. The following recursive function f returns the n-th term of the above sequence:

2. The following function can be used in C++:

unsigned long int f(unsigned long int n)
{
if(n > 1)
return n * f(n - 1);
else
return 1;
}

The following is the whole program:

The following is a trial output of the code:


Related Solutions

Find a sequence {an} whose first five terms are -2, 8/2, -26/6, 80/24, -242/120 …. and...
Find a sequence {an} whose first five terms are -2, 8/2, -26/6, 80/24, -242/120 …. and find if it was converge or diverge
Prove that if (6; a) = (6; b) = 1, then 24 | (a^2 - b^2).
Prove that if (6; a) = (6; b) = 1, then 24 | (a^2 - b^2).
For the following exercises, determine whether the sequence is geometric. If so, find the common ratio. −6, −12, −24, −48, −96, ...
For the following exercises, determine whether the sequence is geometric. If so, find the common ratio. −6, −12, −24, −48, −96, ...
2. Suppose you are given the IS-LM model below: (1) C = 120 + 0.8YD (2)...
2. Suppose you are given the IS-LM model below: (1) C = 120 + 0.8YD (2) I = 300 – 2000r (3) G = 500 (4) T = 400 (5) YD = Y – T (6) Ms = 200 (7) Md = 80 + 0.1Y – 2000r a. Find the equilibrium values of income and the interest rate. b. Suppose you are again given equations (1) – (7), but equation (7) were to be replaced by: (7’) Md = 80...
6. The following sequences are mutations of the template sequence in question 1. For each mutated...
6. The following sequences are mutations of the template sequence in question 1. For each mutated sequence, indicate the new amino acid sequence produced and the type of mutation that is the end result in the amino acid (frameshift, Missense, nonsense, silent) as well as the type of mutation that occurred in the DNA sequence (substitution, addition, deletion) Template sequence question 1: 3’ TACCCTGGTGGTTTGCGGACT 5’ a. 3’ TAC CCG GTG GTT TGC GGACT 5’ b. 3’ TAC ACT GGTGGTTTGCGGACT 5’...
Consider the following time series data: Month 1 2 3 4 5 6 7 Value 24...
Consider the following time series data: Month 1 2 3 4 5 6 7 Value 24 12 20 13 18 24 14 (a) Compute MSE using the most recent value as the forecast for the next period. If required, round your answer to one decimal place. What is the forecast for month 8? If required, round your answer to one decimal place. Do not round intermediate calculation. (b) Compute MSE using the average of all the data available as the...
Print the following two patterns using nested loops. Pattern 1 13579 13579 13579 13579 Pattern 2...
Print the following two patterns using nested loops. Pattern 1 13579 13579 13579 13579 Pattern 2 #####1 ####12 ###123 ##1234 #12345
In this market, price is given by P= 24 - Q/2. Firm 1 moves first, the...
In this market, price is given by P= 24 - Q/2. Firm 1 moves first, the firm 2. The firms have the cost functions C(q)= q^2. 1. Find the marginal revenue for firm 2. 2. What is the reaciton function for firm 2? 3. Find the marginal revenue for firm 1. 4. What is the equilibrium price and quantity?
Sign Runs Test/G Consider the following sequence of 1 and 6: 6 111 66 111 66...
Sign Runs Test/G Consider the following sequence of 1 and 6: 6 111 66 111 66 11 6 11 666 11 6 1111 666 11 66 With a 0.01 significance level, we wish to test the claim that the above sequence was produced in a random manner. Answer each of the following questions (a) The null hypothesis H0 is given by A. n1=n2 B. ρ=0 C. β=0 D. The data are in an order that is not random E. The...
1. Given with the following sample information n1 = 125, n2 = 120; s1 = 31,...
1. Given with the following sample information n1 = 125, n2 = 120; s1 = 31, s2 = 38; x1-bar = 116, x2-bar = 105 Test the following hypotheses, assuming a significance level of 0.05 is to be used with equal variances. Ho : µ1 - µ2 = 0 HA : µ1 - µ2 ≠ 0 What is your conclusion? a) Since t test statistic = 1.82 < t-critical value = 2.49, we do not reject Ho. b) Since t...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT