CS 200 - Lab 7

Factorial

Getting Started

If you have a solution open in Visual Studio, close it (File->Close Solution).

Download lab7.zip.  Import it into Visual Studio (File->Import...).

Add your code to the source file called Fact.c.

Your Task

Prompt the user to enter a positive integer.  Compute the factorial of that number.

The factorial of an integer n is defined as the product computed as follows:

1 * 2 * 3 * ... * n

Example run (user input in bold red):

Enter a positive integer: 6
The factorial of 6 is 720

Hints

Here is a suggested approach:

Your loop variable should be an integer.  Initially, the loop variable should be 1.  Each iteration of the loop should increase the loop variable by 1.  The loop should terminate when the loop variableis greater than the number entered by the user.

A separate variable should be declared to hold the computed product.  It should initially be set to 1.  Each iteration of the loop should multiply the current product by the loop variable, storing the result back into the product variable.