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
What settings are available in the Properties dialog box of a message? Check all that apply.
Reptile [31]

Answer:

A,D,E,F

Explanation:

edg2021

8 0
3 years ago
Read 2 more answers
I’ll give brainliest if answers are correct
irina [24]

Answer:

B and C

Explanation:

A download playback is more reliable because it's stored on the device you're using so there won't be any skipping in during the song.

And it's more portable because you don't need the internet so you can play it anywhere.

It's not D because you still have to wait for it to download before you can play it

Not E because it takes storage on your phone

Not A because the answer for A is a point for streaming

7 0
3 years ago
Write an application that accepts a word from a user and converts it to Pig Latin. If a word starts with a consonant, the Pig La
Scorpion4ik [409]

Answer:

Written in Python

word = input("Word: ")

if(word[0]=='a' or word[0]=='e' or word[0]=='i' or word[0] =='o' or word[0]=='u'):

     print(word+"ay")

else:

     a = word[1:]

     print(a+word[0]+"ay")

Explanation:

<em>The program was written in Python and I've added the explanation as an attachment; where I used comments as explanations</em>

Download txt
7 0
4 years ago
Please help,it’s a year 9 question
KengaRu [80]

Answer:

For an AND gate, Q would be 0,0,0,1 respectively.

See the reference table below.

4 0
3 years ago
Convert the following C program to C++.
ki77a [65]

Answer:

The program equivalent in C++ is:

<em>#include <cstdio></em>

<em>#include <cstdlib></em>

#define SIZE 5

using namespace std;

<em>int main(int argc, char *argv[]) {</em>

<em>int numerator = 25;</em>

<em>int denominator = 10;</em>

<em>FILE * inPut = fopen(argv[1], "r");</em>

<em>FILE * outPut = fopen(argv[2], "w");</em>

<em>float result = (float)numerator/denominator;</em>

<em>fprintf(outPut,"Result is %.2f\n", result);</em>

<em>float arr[SIZE];</em>

<em>for(int i = 0; i < SIZE; i++) {</em>

<em>fscanf(inPut, "%f", &arr[i]);</em>

<em>fprintf(outPut, "%7.4f\n", arr[i]);</em>

<em>}</em>

<em>return 0;</em>

<em>}</em>

Explanation:

See attachment for explanation.

Each line were numbered with equivalent line number in the C program

Download cpp
8 0
3 years ago
Other questions:
  • Write a Python program that will take as input 5 integer values and will output the average of the odd values and the average of
    6·1 answer
  • In python:
    8·1 answer
  • 1. Which of the following is a drone? (1 point)
    10·1 answer
  • How does the View tab of the ribbon allow you to look at a document?
    9·1 answer
  • Take the template and complete creation and ordering of the Triangular Matrix. //Complete the following Functions int**fillAry(i
    7·1 answer
  • Use the Law of Sines to solve the triangle. Round your answers to two decimal places.
    6·1 answer
  • What is a command-line interactive scripting environment that provides the commands for almost any management task in a Windows
    9·1 answer
  • Use MPLAB to write an asemply program to multipy two numbers (11111001) and (11111001). Then save the product in file reisters 0
    8·1 answer
  • 1. Assume that in an implementation of the RSA cryptosystem one modular squar- ing takes 75% of the time of a modular multiplica
    15·1 answer
  • Consider a k=8 block cipher.
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!