Write a function called theSequence that takes a single integer parameter named n. This function should...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
Write a function called theSequence that takes a single integer parameter named n. This function should then calculate and return the n-th integer in the sequence defined above. So, for example: printin(theSequence(1)); // Would output 1 printin(theSequence(2)); // Would output 1 printin(theSequence(3)); // Would output 1 printin(theSequence(4)); // Would output 3 printin(theSequence(5)); // Would output 5 printin(theSequence(6)); // Would output 9 printin(theSequence(7)); // Would output 17 printin(theSequence(7); // Would still output 17 printin(theSequence(7)); // Would always output 17 /l skipping ahead a few... printin(theSequence(37)); // Would output 1467182629 Your function must be able to support values of n arguments from 1 to 37. Your function should not include any hard-coded numbers, other than the number one. Meaning you can't have, for example, the number 31 or the number 1467182629 typed somewhere within your function. Write a function called theSequence that takes a single integer parameter named n. This function should then calculate and return the n-th integer in the sequence defined above. So, for example: printin(theSequence(1)); // Would output 1 printin(theSequence(2)); // Would output 1 printin(theSequence(3)); // Would output 1 printin(theSequence(4)); // Would output 3 printin(theSequence(5)); // Would output 5 printin(theSequence(6)); // Would output 9 printin(theSequence(7)); // Would output 17 printin(theSequence(7); // Would still output 17 printin(theSequence(7)); // Would always output 17 /l skipping ahead a few... printin(theSequence(37)); // Would output 1467182629 Your function must be able to support values of n arguments from 1 to 37. Your function should not include any hard-coded numbers, other than the number one. Meaning you can't have, for example, the number 31 or the number 1467182629 typed somewhere within your function.
Expert Answer:
Answer rating: 100% (QA)
Here i have solved the problem in two ways APPROACH 1 The key to this problem is recursion Here t... View the full answer
Related Book For
Financial Analysis with Microsoft Excel
ISBN: 978-1285432274
7th edition
Authors: Timothy R. Mayes, Todd M. Shank
Posted Date:
Students also viewed these programming questions
-
For AGI and From AGI see calculations below Alice (age 46) and Bruce Byrd (age 48) are married, live in Oklahoma, and file a joint return. Alice is the office manager for Smiles Dental Clinic and...
-
The Balance Sheet of the Street and Highway Fund of the City of Monroe as of December 31, 2019, follow. CITY OF MONROE Street and Highway Fund Balance Sheet As of December 31, 2019 Assets Cash $...
-
Comprehensive Problem On July 31, 2020, the end of its most recent fiscal year, Elizabeth River Business Consultants' post- closing trial balance was as follows: Accounts Debit Credit Cash $ 26,150...
-
Top Bun, an international bread empire that reports under IFRS. Their fiscal year-end is December 31, 2022. They began the year on January 1, 2022 with 102116 common shares. They issued 56760 common...
-
In problems, a slop field is given for a differential equation of the form y' = f(x,y). Use the slope field to sketch the solution that satisfies the given initial condition. In each case, find...
-
A village currently carries water by hand from a lake that is 1200 m from the village center. It is later determined that the surface of the lake is 3 m above the elevation of the village, so someone...
-
Plaintiffs James and Betty Tonkovich own approximately 850 acres of in Belmont County, Ohio. Plaintiffs belong to a group of landowners known as Belmont Leasing Group, which leases land for oil and...
-
Weston Corporation manufactures auto parts for two leading Japanese automakers. Nancy Evans is the management accountant for one of Westons largest manufacturing plants. The plants general manager,...
-
Complete the table for the point (2, 2). f(x) (2, 2) f(2x) 6f(2x) 6f(2(x+1))- -3
-
A highway has an optional toll lane that drivers may take to reduce the time they spend driving. Drivers pay a small fee to enter the toll lane ($0.25). Then, once they leave the toll lane, they pay...
-
Stakeholders who want to look at detailed financial information on whether a company is profitable, is able to pay its bills, and how much debt it owes will look at the firm's _____. financial...
-
As discussed in the article "Federal Corporate Law: Lessons from History" one political impediment to sweeping federal change is the presumption in favor or state law in corporate matters. How might...
-
The Summit at Crystal Mountain is a small ski resort located just outside Mount Rainier, Washington; approximately 100 miles from Seattle. The resort consists of slopes that appeal to skiers of...
-
John has a job selling souvenirs at a football stadium. He earns $10 per game plus $0.25 for each souvenir he sells. How many souvenirs does John need to sell to earn a total of $35 for working at...
-
To support herself while attending school, Daun Deloch sold stereo systems to other students. During the first year of operations, Deloch purchased the stereo systems for $163,000 and sold them for...
-
It is important for all to understand what sources of data and statistical tools are available. Your assignment is to research and identify what tools are used frequently within your organization....
-
What was Thomas Malthuss theory? what it has impact on growth ?
-
For a nonzero constant a, find the intercepts of the graph of (x 2 + y 2 ) 2 = a 2 (x 2 - y 2 ). Then test for symmetry with respect to the x-axis, the y-axis, and the origin.
-
You have decided to investigate a number of exchange-traded funds (ETFs) in an attempt to build a diversified portfolio. You believe that the transportation, consumer goods, energy, financials, and...
-
In your position as research assistant to a portfolio manager, you need to analyze the profitability of the companies in the portfolio. Using the data for 3M Co. below: a. Calculate the net profit...
-
A stock's beta coefficient can be calculated using the following equation: B- = ^2 Vi, a. Write a user-defined function that can calculate the beta coefficient. The arguments to the function should...
-
The commercial division of a real estate firm is conducting a regression analysis of the relationship between x, annual gross rents (in thousands of dollars), and y, selling price (in thousands of...
-
The Transactional Records Access Clearinghouse at Syracuse University reported data showing the odds of an Internal Revenue Service audit. The following table shows the average adjusted gross income...
-
Refer to the data in exercise 31. Consider a model in which only Industry is used to predict Delay. At a .01 level of significance, test for any positive autocorrelation in the data. Data From...
Study smarter with the SolutionInn App