1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Serjik [45]
3 years ago
10

C++ code-- Factorial Recursion

Computers and Technology
2 answers:
Aloiza [94]3 years ago
3 0
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 ) );
}
oksano4ka [1.4K]3 years ago
3 0

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);

}

}

You might be interested in
Which one of them are the correct answers?
Tpy6a [65]

Rapid prototyping! I am sure that is correct


6 0
3 years ago
The convergence of information technology and operations technology, offering the potential for tremendous improvements in effic
11111nata11111 [884]

Answer:

<em>e. Industrial Internet of Things</em>

Explanation:

The industrial Internet of Things (IIoT) <em>is the use of intelligent detectors and actuators to improve manufacturing processes and production. </em>

IIoT utilizes the power of intelligent machines and real-time big data to take full advantage of data produced for years by "dumb" machines in industrial settings.

7 0
3 years ago
If you have an array of 100 sorted elements, and you search for a value that does not exist in the array using a binary search,
Juli2301 [7.4K]

Answer:

50

Explanation:

as binary search will search the array by dividing it into two halves till it find the value.

7 0
2 years ago
Which of the following is NOT part of the Ethernet standards? O 1.802.3 O 2.802.2 O 3 LLC O4 pPp
mote1985 [20]

Answer: 2) 802.2

Explanation: Ethernet standard are the standard for the networking technology for the transmission of the data.The ethernet is requires for the node connection and then forming the framework for the transmission of information.There are several standards for Ethernet.

802.3 is Ethernet standard that works on 10 Mbps rate, PPP(point to point protocol) is the standard that connects the internet service provider using modem and LLC(logical link control) is a standard for 802 .There is no 802.2 standard present in the ethernet standard.Thus,the correct option is option(2).

7 0
2 years ago
The product of joint force development is a _____________.
sleet_krkn [62]

Answer:

trained and capable joint force.

Explanation:

The joint force development policy is in regards to the training and recruitment of military officials, to improve or promote the growth and speedy development of recruits in the United States military.

Several aspects of military training are given to officials by joint parties from different but collaborating organizations. Joint education, deployment, and dissemination of employment various members of the armed forces are encouraged.

7 0
3 years ago
Other questions:
  • Amitha writes up a one-page summary of a novel during her summer internship at a publishing company. When she reads over the pag
    10·1 answer
  • Choose a film you have watched, or watch a film you have wanted to. Write a film review in at least three paragraphs. Describe w
    5·1 answer
  • Explicit knowledge can be documented and codified, whereas tacit knowledge encompasses insights, judgment, creative processes, a
    9·1 answer
  • What is an advantage of a computer network ? networked
    13·2 answers
  • The purpose of a function that returns "void" is:_________. A) To satisfy compiler warnings B) To package a repeated task as a f
    7·1 answer
  • Write a program that uses a dictionary to store students birthdays. Your program should ask the user what their name is, and loo
    11·1 answer
  • Help me and i'll mark brainliest
    9·1 answer
  • The input nums is supposed to be an array of unique integers ranging from 1 to nums.length (inclusive). However, there is a mist
    12·1 answer
  • What year does futurist ray kurzweil believe ai will meet human intelligence?.
    7·2 answers
  • Why is a salt added to a password that is being stored in a database?
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!