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
List some of the CSS and HTML code that is confusing to you. List at least three CSS attributes and three HTML tags.
svet-max [94.6K]

Answer:

HTML Tags: <input/>, <canvas></canvas>, <div></div>

CSS Attributes: padding, font-family, margin

Explanation:

5 0
3 years ago
Read 2 more answers
5) How is the operating system on a desk top computer different from the operating system on a smart phone?​
lesya692 [45]
The difference is that system on a desk top preforms all the basic tasks like file management, memory management handling input and output and controlling peripheral devices such ad disk and printers where as some smart phone work on specific hardware
6 0
3 years ago
The _____ address range is reserved for a computer to communicate with itself and is called the loopback.
Papessa [141]
The answer is 127 I had that question before
4 0
3 years ago
Which are elements involved in modeling a solution? Choose all that apply. A) often includes a visual graphic B) shows the flow
Diano4ka-milaya [45]
Need to know how to read Circuit diagramed
6 0
3 years ago
Read 2 more answers
A file type is the standard used to and information in a computer. All file types have unique that determine which program to us
Oxana [17]

The term record types portrays the assortment of relationship among archives and the applications that utilization them. The most clear utilization of this component is that, for instance, Windows knows to run Notepad when you double tap on a book report in Explorer (confirmation that Windows XP isn't genuinely question arranged).

Genuine object-situated configuration manages that articles (for this situation, records and envelopes) know about their very own attributes. This plan is just copied in Windows XP. Rather than each record knowing which application is utilized to alter it, Windows decides how to deal with a document dependent on the filename expansion. This structure has points of interest and weaknesses, however Microsoft's choice to shroud filename augmentations, the reason for record affiliations, just makes the entire framework increasingly hard to comprehend and ace.

Everything begins with document augmentations, the letters (normally three) that pursue the period in many filenames. For instance, the augmentation of the record Readme.txt is .txt, connoting a plain-content document; the expansion of Resume.wpd is .wpd, implying an archive made in WordPerfect. Naturally, Windows shrouds the expansions of enlisted record types in Explorer and on the work area, however it's ideal to have them shown.

Record expansions not just enable you to effectively figure out what sort of document a specific document is (on the grounds that symbols are never unmistakable enough), yet additionally enable you to change Windows' view of the kind of a record by essentially renaming the augmentation. Note that changing a document's augmentation doesn't really change the substance or the organization of the record, just how Windows associates with it.

To show your document augmentations, open Folder Options in Control Panel (or from Explorer's Tools menu), pick the View tab, and mood killer the Hide expansions for realized record types alternative. Snap OK when you're set.

By concealing record expansions, Microsoft wanted to make Windows simpler to utilize—an arrangement that exploded backward for a few reasons. Since just the expansions of enrolled documents are covered up, the augmentations of records that aren't yet in the File Types database are still appeared. Even all the more confounding that, when an application at long last claims a specific document type, it can appear to the unpracticed client just as the entirety of the old records of that type have been renamed. It likewise makes an "information hole" between the individuals who comprehend document types and the individuals who don't; take a stab at telling somebody whose PC still has concealed augmentations to discover Readme.txt in a catalog loaded with records. Different issues have emerged, for example, attempting to separate Excel.exe and Excel.xls in Explorer when the expansions are covered up; one record is an application and the other is a report, however they might be generally undefined.

Redo Context Menus

A setting menu (once in a while called an alternate route menu ) is the little menu that shows up when you utilize the correct mouse catch to tap on a record, envelope, application titlebar, or almost some other item on the screen. More often than not, this menu incorporates a rundown of activities proper to the item you've clicked. As it were, the alternatives accessible rely upon the specific circumstance.

The setting menu for documents, the most ordinarily utilized and altered setting menu, relies on the sort of record chosen, which is dictated by the filename augmentation. For instance, all content documents (with the .txt augmentation) will have a similar setting menu, paying little respect to what they contain or which application was utilized to make them. (This is the reason Windows gives you a harsh admonition when you attempt to change a document's expansion.)

4 0
3 years ago
Other questions:
  • _______________ is used by a hacker to mask intrusion and obtain administrator permissions to a computer.
    7·1 answer
  • 1. What conversion factor should be used to convert from Gigaliters to liters?
    14·1 answer
  • PLEASE ANSWER THIS IM IN A QUIZ
    15·2 answers
  • You are requesting information about wireless connectivity for your workplace computers. Because you expect the information to b
    15·1 answer
  • Which statement best describes network security
    8·2 answers
  • Did anyone else remember that Unus Annus is gone? I started crying when I remembered.... Momento Mori my friends.... Momento Mor
    9·2 answers
  • Question 1 of 30
    13·1 answer
  • . What is a computer network? *
    9·1 answer
  • Bank of America sends out customer surveys to all of its customers asking them about the services they offer. What type of resea
    15·1 answer
  • 8.
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!