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
Computer Science & Information Technology
You might also like to view...
Passwords, Internet use, email attachments, software installation, instant messaging, and desktop configuration are areas of ______
a. Computer policies b. User policies c. Documentation d. Network policies
Computer Science & Information Technology
If an application hangs up, you can use the ____ to close a non-responding program.
A. Task Manager B. Help window C. Project Manager D. virus software
Computer Science & Information Technology