Here is a recursive function that is supposed to return the factorial. Identify the line(s) with the logical error(s). Hint: This compiles and runs, and it computes something. What is it?
What will be an ideal response?
```
int fact( int n ) //a
{
int f = 1; //b
if ( 0 == n || 1 == n ) //c
return f; //d
else
{
f = fact(n - 1); //f
f = (n-1) * f; //g
return f; //h
}
}
```
The function computes (n-1)! The logical error is in line g) which should be
f = n * f; rather than
You might also like to view...
Which of the following will not duplicate a slide for your presentation?
A. Click the slide you want to duplicate, then use the Copy and Paste buttons on the HOME tab. B. Left-click a slide and use the shortcut menu's Copy and Paste options. C. Right-click a slide and use the shortcut menu's Copy and Paste options. D. Click the slide you want to duplicate, then select Duplicate Selected Slides.
The term ____________________ refers to the study of moral standards and how they affect our conduct in daily life.
Fill in the blank(s) with the appropriate word(s).
The ________ feature enables you to preview a formatting change to your selected text
A) Live Preview B) Backstage view C) Mini toolbar D) Print Preview
The ________ ratio is the ratio of an object's width in regard to its height
Fill in the blank(s) with correct word