int factorial (int n) { /* Calculate a factorial using loop. * A factorial of a number is the product * of the number itself times the factorial * of the number minus 1; i.e n! = nx (n-1) x ..1 */ } int f = -1; if (n < 0) { cout << "Error, Factorial: Negative argument. << \n; } else { f = 1; for (int i=2; i

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter8: Arrays And Strings
Section: Chapter Questions
Problem 10PE
icon
Related questions
Question

Write out possible test paths based on the image given 

int factorial (int n) {
/* Calculate a factorial using loop.
* A factorial of a number is the product
* of the number itself times the factorial
* of the number minus 1; i.e n! = nx (n-1) x ..1 */
}
int f = -1;
if (n < 0) {
cout << "Error, Factorial: Negative argument."
<< \n;
} else {
f = 1;
for (int i=2; i<=n; i++)
f = f*i;
*
}
return (f);
Transcribed Image Text:int factorial (int n) { /* Calculate a factorial using loop. * A factorial of a number is the product * of the number itself times the factorial * of the number minus 1; i.e n! = nx (n-1) x ..1 */ } int f = -1; if (n < 0) { cout << "Error, Factorial: Negative argument." << \n; } else { f = 1; for (int i=2; i<=n; i++) f = f*i; * } return (f);
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps with 5 images

Blurred answer
Knowledge Booster
Program on Numbers
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning