-4

I have a problem understanding what this means:

"Write a function calculating the factorial of a number using the largest possible, appropriate return type. This function will have one parameter, and will return the factorial of that number. The program needs to stop working when the numbers get too large to fit in your variables. Test your function by calling it from main(). Call the function in a loop, and output the results like this:"

Factorials:

1: 1
2: 2
3: 6
4: 24
5: 120
… etc.

Fiddling Bits
  • 8,712
  • 3
  • 28
  • 46

1 Answers1

0

In a loop, calculate the factorial for a given n. For each iteration, use printf to show the current state of your factorial calculation. Choose a return type that can hold the largest possible factorial. If a calculation will get too large, and cause an overflow, cap the calculation at the previous value.

The stub of your calculate factorial function will be something like this:

unsigned long long calculateFactorial(int n)
{
    unsigned long long factorial;

    /* Create a loop to calculate the factorial of n. */
    /* Print the progress of your calculation using   */
    /* %llu as your printf format specifier.          */

    return factorial;
}
Fiddling Bits
  • 8,712
  • 3
  • 28
  • 46