Printing 100 factorial

Printing 100 factorial using C++ sounds to be easy. But please note that it is not capable of storing the no. of digits 100! contains. (LONG DOUBLE MAY STORE ONLY UPTO 19 DIGITS). But still C++ can do what calculators can't. Can any body tell me how 100 factorial be printed using C++.( note : - char i to a...may be used).

Your reply will be greatly appreciated.

We can't do your assignment for you. You should only ask for help on specific C++ matters.
One way would be to store the digits of individual numbers in an array. For this problem involving 100 factorial, it is helpful to know that you'll need to hold 158 digits for your final answer. Create the appropriately sized array, but realize that your program will not work for 101 factorial since arrays sizes have to be hard-coded prior to compiling.

In my array-based solution, I discovered that it was easier to store my digits backwords in the array and then simply multiply from right to left. I'm leaving out a lot of details in this part.

Hope this helps you get started with one possible approach.



I think a container would be better than an array for this
A vector would take care of the dynamic memory allocation without having to jump into pointers. I'm not familiar with container objects yet. Just did a quick search - looks complicated.
Topic archived. No new replies allowed.