C++ code-- Factorial Recursion
Write code to complete PrintFactorial()'s recursive case. Sample output if userVal is 5:
5! = 5 * 4 * 3 * 2 * 1 = 120
#include
using namespace std;

void PrintFactorial(int factCounter, int factValue){
int nextCounter = 0;
int nextValue = 0;

if (factCounter == 0) { // Base case: 0! = 1
cout << "1" << endl;
}
else if (factCounter == 1) { // Base case: Print 1 and result
cout << factCounter << " = " << factValue << endl;
}
else { // Recursive case
cout << factCounter << " * ";
nextCounter = factCounter - 1;
nextValue = nextCounter * factValue;


}
}

int main() {
int userVal = 0;

userVal = 5;
cout << userVal << "! = ";
PrintFactorial(userVal, userVal);

return 0;
}

Answers

Answer 1
Handle the print outside of the factorial function, which only needs one userVal when called.

int factorial( int foo )
{
  if( foo == 1 )
   return 1;
 else
   return( foo * factorial( foo - 1 ) );
}
Answer 2

Answer:

void PrintFactorial(int factCounter, int factValue){

int nextCounter = 0;

int nextValue = 0;

if (factCounter == 0) { // Base case: 0! = 1

cout << "1" << endl;

}

else if (factCounter == 1) { // Base case: Print 1 and result

cout << factCounter << " = " << factValue << endl;

}

else { // Recursive case

cout << factCounter << " * ";

nextCounter = factCounter - 1;

nextValue = nextCounter * factValue;

printFactorial(nextCounter, nextValue);

}

}

Explanation:

The only things that is left is calling the recursive function in the else statement. It is the bolded command on the answer.

factCounter is the value we are multiplying. In the function, it is nextCounter. So for 5, it is 5, then 4, then 3, until 0...

factValue is the value of the factorial. In the function, it is nextValue So it is 5, then 5*4 = 20, then 5*4*3 = 60, then...

void PrintFactorial(int factCounter, int factValue){

int nextCounter = 0;

int nextValue = 0;

if (factCounter == 0) { // Base case: 0! = 1

cout << "1" << endl;

}

else if (factCounter == 1) { // Base case: Print 1 and result

cout << factCounter << " = " << factValue << endl;

}

else { // Recursive case

cout << factCounter << " * ";

nextCounter = factCounter - 1;

nextValue = nextCounter * factValue;

printFactorial(nextCounter, nextValue);

}

}


Related Questions

Which of the following strategic issues needs to be addressed in a successful software testing process?
A) conduct formal technical reviews prior to testing
B) specify requirements in a quantifiable manner
C) use independent test teams
D) wait till code is written prior to writing the test plan
E) both a and b

Answers

The strategic issues that should be addressed for a successful software testing process include the conducting of a formal technical reviews prior to testing and specifying the requirements in a quantifiable manner.

The test strategy has to do with the testing approach of the development cycle of the software and its aim is to ensure that the objectives of the software are met.

It should be noted that using independent test teams and waiting till the code is written prior to writing the test plan doesn't need to be addressed in a successful software testing process.

Therefore, the correct option is E since both option and B are correct.

Read related link on:

https://brainly.com/question/13262403

By collecting software metrics and making use of existing software reliability models it is possible to develop meaningful guidelines for determining when software testing is finished.
A) TRUE
B) FALSE

Answers

B) False, bug testing and updates are always needed.

What type of Microsoft Server serves as an email server?

Answers

I have a feeling you're looking for Microsoft Outlook.
Outlook. Outlook is the new email server by Microsoft and is was made on July 31, 2012!

Why are words like monkey, smile, and freedom not good to use as passwords??

Answers

Because those type of words are very simple to figure out so what you need is a more complex password like with number and symbols

well maintained websites may have an unmaintaned page that has not been updated

Answers

Yes, and no, some sites do have these, but ones that are developed by many teams of people and are updated constantly, do not have unmaintained and incomplete pages. 

the internet is an example of

a. a large multi user program
b. a computer program
c. wireless connection
d. mass file storage

Answers

The internet is an example of a large multi-user program. Thus the correct answer is A.

What is the internet?

The Internet is refers to a Network of thousands of computers used to connect people from miles away. This has shortened the distance between people.

It helps to communicate, do online shopping, education, research, play games, animations, and so on. It allows many people to connect over the program.

Therefore, option A  a large multi-user program is the appropriate answer.

Learn more about the Internet, here:

https://brainly.com/question/13308791

#SPJ2

Antel and imd both produce similar computer chips and the two companies dominante this

Answers

Answer:

Because it will restrict the supply of computer chips

Explanation:

Antel and imd both produce similar computer chips and the two companies dominante this

Because they can both charge more for the product at the given level of production

Because it will restrict the supply of computer chips

Because overall demand for computer chips will increase

Because the firms' marginal costs increase as output increases

As both companies have the total supply of the product in the market they can dominate everything that they are providing because of this, they cab restrict the supply of the computer chips, if they cooperate and work together they can set a minimum price and a ceiling price, they can dictate how the market flows, because of that, the price of the computer chips will depend solely on them.

i have a couple of questions on java for my homework

21229

Assume the availability of a method named makeLine that can be passed a non-negative integer n and a character c and return a String consisting of n identical characters that are all equal to c. Write a method named printTriangle that receives two integer parameters n andk. If n is negative the method does nothing. If n happens to be an even number, its value is raised to the next odd number (e.g. 4-->5). Then, when k has the value zero, the method prints a SYMMETRIC triangle of O's (the capital letter O) as follows: first a line of n O, followed by a line of n-2 O's (indented by one space), and then a line of n-4 O's (indented by two spaces), and so on. For example, if the method received 5,0 (or 4,0) it would print:
OOOOO
OOO
O
Note: in the above output , the first line contains 0 spaces before the first O, the next line 1 space, and so on.
Note: These instructions state what the method does when k is zero, but it is up to you, the programmer, to determine what it does when k is not zero and use it for your advantage.
The method must not use a loop of any kind (for, while, do-while) to accomplish its job. The method should invoke makeLine to accomplish the task of creating Strings of varying lengths.

20861

A palindrome is a string that reads the same forwards or backwards; for example dad, mom, deed (i.e., reversing a palindrome produces the same string ). Write a recursive, boolean -valued method , isPalindrome that accepts a string and returns whether the string is a palindrome.
A string , s, is a palindrome if:

s is the empty string or s consists of a single letter (which reads the same back or forward), or
the first and last characters of s are the same, and the rest of the string (i.e., the second through next-to-last characters ) form a palindrome.

20864

A 'array palindrome' is an array which, when its elements are reversed, remains the same (i.e., the elements of the array are same when scanned forward or backward) Write a recursive, boolean -valued method , isPalindrome, that accepts an integer -valued array , and a pair ofintegers representing the starting and ending indexes of the portion of the array to be tested for being a palindrome. The function returnswhether that portion of the array is a palindrome.
An array is a palindrome if:

the array is empty (0 elements ) or contains only one element (which therefore is the same when reversed), or
the first and last elements of the array are the same, and the rest of the array (i.e., the second through next-to-last elements ) form a palindrome.

Answers

In C, strings aren't a data type. Strings are handled as an array of char (acters). Therefore, your two palindrome assignments are basically the same.

Recursion is something that is probably the most mind warping thing to learn in programming, but it is VERY well worth it. There's a number of problems that are recursive in nature. One that you're familiar with is doing addition with pencil and paper.  Think about it: you align the numbers in columns as you're "going in", when you run out of numbers, the base case, you start adding the column of numbers and the carry and write out the least significant digit of the total and returning the most significant digit[s] up the "unwind".

The _____ address range is reserved for a computer to communicate with itself and is called the loopback.

Answers

The answer is 127 I had that question before

Which of the following is an approach to debugging?
A) backtracking
B) brute force
C) cause elimination
D) code restructuring
E) a, b, and c


Answers

C) cause elimination

The following is an approach to debugging:

A) backtracking

B) brute force

C) cause elimination

There are different approaches to debugging a Software Applications, these are:

Brute Force Method: This method commonly used but it has the least efficiency for isolating the cause of a software error.Back Tracking Method: This method is commonly used for small applications.Cause Elimination: The approach involves induction or deduction.

Find out more at: https://brainly.com/question/23959780

keeping in mind the role in order of precedence plays in equations, what would excel display as the result of the following equation? (24+75)/(6*3)

Answers

5.5
it is not equation

________ is a collection of many separate networks.
A) A WAN
B) An internet
C) a LAN
D) None of the above

Answers

B.) An internet- a collection of networks

Which term describes the order of arrangement of files and folders on a computer?

Answers

Its called Folder window if you have a window 7 

Assign True to the variable has_dups if the string s1 has any duplicate character (that is if any character appears more than once) and False otherwise.



Here is the answer I wrote:


i = []
for i in range(len([s1])):
if s1.count(s1[i]) > 1:
has_dups = True
elif s1.count(s1[i]) = 1:
has_dups = False


Here is the message I got from the system:

Solutions with your approach don't usually use: elif



Please Help me to correct it.

Answers

i dont know the language of the code
probably you have sintacs mistakes in it

has_dups = false
for i in range(len([s1])):
has_dups = has_dups || s1.count(s1[i]) > 1

Regression testing should be a normal part of integration testing because as a new module is added to the system new
A) control logic is invoked
B) data flow paths are established
C) drivers require testing
D) all of the above
E) both a and b

Answers

Regression testing should be a normal part of integration testing because as a new module is added to the system new control logic is invoked and data flow paths are established.

What is regression testing?

Regression testing is a software testing practice which ensures that an application is still functioning as it need to or expected after making any code changes or improvements. Regression testing checks for the overall stability and functionality of the existing features of the software.

Now, the Regression testing is integrated with the software so that if any changes are made, new control logics are automatically invoked and data flow path is established.

Thus, the correct option is E. i.e. both A and B.

Learn more about regression testing.

https://brainly.com/question/13327687

#SPJ2

Which topology requires a central controller or hub?
A) Mesh
B) Star
C) Bus
D) Ring

Answers

I Think it is Topology of star but I am not sure.

Each component of a network is connected to a central node, frequently referred to as a hub or switch, in a star architecture. Thus, option B is correct.

What topology requires a central controller or hub?

A benefit of star topologies is that just the central site needs to be modified, making it simple to add new sites. The centre site is crucial in a star topology; if it fails, all connections would be lost. The connection's performance is determined by how well the central hub functions.

A star network is a local area network (LAN) topology in which all nodes, such as personal computers (PCs), workstations, or other devices, are directly connected to a single common hub, which is frequently referred to as a central computer. As a result, a hub-and-spoke network structure is another name for a star network.

Therefore, Star topology requires a central controller or hub.

Learn more about topology here:

https://brainly.com/question/10536701

#SPJ2

A ______ is a data communication system spanning states, countries, or the whole world.
A) MAN
B) LAN
C) WAN
D) none of the above

Answers

C.) WAN (Wide Area Network)

A WAN is a data communication system spanning states, countries, or the whole world. Thus, option C is correct.

What is data communication?

Data communication is the process of sending messages or data through two devices across a wireless medium, as it is in computer systems. A combination of hardware and connectivity is used in this procedure.

A communications system known as a large area network covers a huge geographic region. Leased telecommunications lines are frequently used to construct large-area networks.

Since this includes numerous stations dispersed across a particular bregion, or perhaps the entire world, it is known as a wide-area network. This was to ensure that the data can be reached, by multiple users.

Therefore, option C is the correct option.

Learn more about data communication, here:

https://brainly.com/question/28588084

#SPJ2

In your opinion, is it more beneficial to have many folders or is it better to “nest” subfolders? Explain your response.

Answers

You can have one folder such as "Workspace" and have multiple different sub-folders that relate that to "Workspace". Also if you store pictures in a folder, it might be a good idea to separate them into different sub-folders.

Like one set of pictures could be in the sub-folder "2015-2016". All your pictures from 20015 to 2016 could be in that folder.
I think it's better to have multiple folders because for say you have 6 school subjects but only have 1 folder how are you going to keep track with all 6 subjects in one folder ? You could use each folder for each subject which would save you a lot of time when it comes to getting out your complete work .

What object type would you use to identify the address of the neighbouring gateway from your local gateway?

Answers

You would use a gps or a map
You would use a route map

A(n) ____ is a front-end processor that multiplexes the traffic from hundreds of remote terminals into one port on a large computer.

Answers

I think it'd be terminal concentrator.  A(n) terminal concentrator is a front - end processor that multiplexes the traffic from hundreds of remote terminals into one port on a large computer. 

Acceptance tests are normally conducted by the
A) developer
B) end users
C) test team
D) systems engineers

Answers

The answer is D. System engineers

B: End Users

That is the correct answer

How many passwords can be created in the form [a - z][a - z]9[0, 1]6? that is, a capital letter followed by 9 lowercase letters followed by 6 bits.?

Answers

no capital letters expected
26 * 26^9*2^6 = 9034694121816064

_______ is the protocol suite for the current Internet.
A) TCP/IP
B) NCP
C) UNIX
D) ACM

Answers

A? not very sure sorry

The method needed to arrange for an object to be notified when a window's close-window button has been clicked is

Answers

The correct answer that would best complete the given statement above would be the term addWindowListener. The method needed to arrange for an object to be notified when a window's close-window button has been clicked is addWindowListener. Hope this is the answer that you are looking for. 

A circuit has a voltage of 24 V and a current of 40 mA. What is the power of the circuit?

A. 6 W
B. 9.6 W
C. 6.24 W
D. 0.96 W

Answers

Hi! There is a relation between voltage, current, and power. It's very simple, too! It's voltage multiplied times current.
[tex]P=IV[/tex]
or [tex]VI=P[/tex] might be easy to remember because V.I.P. (like V.I.P. stadium seating)

Then you just have to work with units to get watts. Watts is volt-amps.

You can convert at any point to get watts as the unit. I'll turn the current to amps first.
[tex]40\text {mA}\cdot\frac{1\text A}{1000\text{mA}}=0.040\text A[/tex]
Then, multiply [tex]VI=P[/tex]
[tex]24\text V\cdot0.040\text A=0.96\text V\cdot\text A = 0.96\text W[/tex]

which of the following is the default letter assigned for the primary hard drive

Answers

The drive letter is C. C:\

Debugging is not testing, but always occurs as a consequence of testing.
A) TRUE
B) FALSE

Answers

A) True Hope that helps

It is true to say that Debugging is not testing but always occurs as a consequence of testing.

What is Debugging?

Debugging is the process of identifying and fixing defects in computer programs, software, or systems. It is a crucial step in computer programming and software development.

Debugging is used to identify and correct errors. The testing procedure just displays the consequences of the coding fault on the application; it does not assist the developer in identifying the mistake in the code.

Software developers and engineers use debugging to find and correct bugs in programs before making them available to the general public. It's an additional step to testing, which entails discovering how an issue impacts a program as a whole.

Debugging is the act of locating and fixing problems in software code that might lead to unexpected behavior or crashes. These mistakes are sometimes referred to as "bugs." Debugging is used to identify and fix faults or flaws in software or systems so that they don't operate incorrectly.

To read more about Debugging, refer to - https://brainly.com/question/13966274

#SPJ2

Given the ip address 192.168.112.0. each network requires between 35 and 60 hosts. what is the broadcast address of the first available subnet?

Answers

Its is 255.255.255.0

What two tasks need to be done after installing a secondary hard drive?

Answers

Make sure everything is connected, then turn it on and see if it works.



XML Schemas consist of:
A.
properties and methods.
B.
elements and attributes.
C.
structure and data.
D.
tables and relationships.
View Answer Workspace Report Discuss in Forum
9.
The expression FOR XML RAW tells SQL Server to:
9.
A.
place the values of the columns as attributes in the resulting XML document.
B.
place the values of the columns into elements rather than attributes.
C.
place some columns into elements and others into attributes.
D.
None of the above is correct.

Answers

none of the above is correct
Other Questions
What effect did Emperor Ashoka have on Buddhism? He led a reformation of the Buddhist religion. He outlawed every religion except Buddhism. He spread Buddhism to areas outside of India. He arrested and attacked Buddhists in his empire. simplify the ratio 12:2 ...? give an example of coyote shows his foolish trickster nature Shanti has just joined a DVD rental club. She pays a monthly membership fee of $4.95, and each DVD rental is $1.95. If Shanti's budget for DVD rentals in a month is $42, how many DVDs can Shanti rent in her first month if she doesn't want to go over her budget? ________ DVDs Monica likes chicken. Help her plan her diet by identifying the daily serving size for the food group that includes chicken. 1 ounce 2 to 3 ounces 5 to 6 ounces 10 to 12 ounces PLEASE help!. When Secretary William H. Seward purchased Alaska in 1867, newspapers ridiculed him. What 1898 event changed Americans minds about Alaska being called Sewards Ice Box and Icebergia?A.the drilling of an oil gusherB.a trade treaty with RussiaC.the discovery of goldD.an expedition to the North Pole 5x^2-3y^2-20x+6y+2=0 what is the value of a What is Best Buy out of 3 lbs for 1.89 or 5lbs for 2.49 How did ww2 actually start? What's the independent variable?What the dependent variable?What is the average number of deer per month? Read the sentence.If your bicycle tire is low, use a pump to fill it with air.Which word is the direct object in the sentence?bicycletirepumpit Which statement best reflects the purpose of satire?A. It uses wit and irony to persuade its audience to pursue social change.B. It entertains the readers with its humor and plot twists.C. It informs its audience about social or political issues in a direct manner.D. It shares a life-changing personal experience with its readers. Find the simplified form of the expression. Give your answer in scientific notation. (9 x 10 5)(6 x 10 -7) A. 5.4x 10 -34 B. 1.5x 10 -1 C. 5.4x 10 -1 D. 1.5 x 10 -34 When combined in the correct ratio, hydrogen and oxygen atoms can form water. These particles that water is made of are example of DNA is spread out in the nucleus of a cell of non-dividing cells it is called ___________ Find the natural abundance of Mg-26. Write a story about a time that you helped someone else When weaving quotes into your literary analysis essay, make sure they fit grammatically with your own sentence structure. If needed, you canA. make a change to the quote (which does not change the meaning) and indicate it with brackets.B. use the original quote but add an explanation at the end about the grammatical inconsistency.C. make a change to the quote (that does not change the meaning) and indicate it with commas. A strong mayor in the mayor council system has the authority to With what magnitude of force does a ball of mass 0.75 kilograms need to be hit so that it accelerates at the rate of 25 meters/ second 2 ? Assume that the ball undergoes motion along a straight line.A. 10 newtonsB. 19 newtonsC. 33.3 newtonsD. 40 newtons