Seventh Assignment, due 19th November 2002

Factorials

Electronic Submission, hw7

 
Write a program that calculates and prints exact factorials of numbers entered by the user. The numbers entered will be integers in the range 0 to 1000.

Your program must follow an exact specification for input and output. It should print no prompt, just allowing the user to enter an integer. If the number entered is negative, the program should stop without producing any further output. If the number is between 0 and 1000, the program should print on one line, exactly: the number entered, followed by the factorial sign '!', followed by one space, followed by an equals sign '=' followed by one space, followed by the exact factorial of the number in decimal, with no leading zeros. After producing this output, the program should continue from the beginning, allowing the user to enter another number.

Here is a sample transcript of a session with your program. What the user types is underlined.
$ a.out
3
3! = 6
5
5! = 120
0
0! = 1
1000
1000! = 4023........0
11
11! = 39916800
-1
$

Note that for 1000! you should not print the dots as above, you should print the actual digits of the factorial of one thousand.

Of course you may make your program produce extra output while you are developing or debigging it, but remember to remove all extra output before submitting.

You may test you solution using the Automatic Judging System; this homework assignment appears as problem number 114.