(Factorials) The factorial function is used frequently in probability problems. Using the definition of factorial in Exercise 3.34, write a program that uses a for statement to evaluate the factorials of the integers from 1 to 5. Print the results in tabular format. What difficulty might pre- vent you from calculating the factorial of 20?

What will be an ideal response?


Calculating the factorial of 20 might be difficult, because it might be such a large
number that it would not fit in an int or long variable.
// Factorial program.
#include
using namespace std;

int main()
{
int factorial = 1; // current factorial value

// display table headers
cout << "x\tx!\n";

// display factorial of numbers 1-5
for ( int i = 1; i <= 5; i++ )
{
factorial *= i; // i!

// display factorial value in table
cout << i << '\t' << factorial << '\n';
} // end for

cout << endl;
} // end main

Computer Science & Information Technology

You might also like to view...

Because resolution is so closely associated with image quality, resizing an image may have a negative effect on its appearance.

Answer the following statement true (T) or false (F)

Computer Science & Information Technology

Information is ________ using a key. In Access, the key will be a password. In other applications, the key can be a separate file

A) decrypted B) secured C) encrypted D) shared

Computer Science & Information Technology

In a Find duplicates query, it does not matter which table is chosen first

Indicate whether the statement is true or false

Computer Science & Information Technology

Each of the following statements is TRUE about referencing data between worksheets EXCEPT:

A) One of Excel's more powerful features is the ability to reference data between worksheets. B) Multiple worksheets represent a second dimension. C) If you think of a worksheet as a two-dimensional array, then multiple worksheets in a workbook can be thought of as a three-dimensional array. D) By using a 3-D formula with 3-D references, you can easily create a summary worksheet from multiple worksheets that are updated automatically as the source data is updated.

Computer Science & Information Technology