Thread: 500!
View Single Post
Old Jun 24th, 2005, 8:43 AM   #2
grumpy
Programming Guru
 
grumpy's Avatar
 
Join Date: Jun 2005
Location: Adelaide, South Australia
Posts: 1,315
Rep Power: 5 grumpy will become famous soon enough
Quote:
Originally Posted by Lina
How we can calculate and output the value of 500!. Namely, how one can deal with a huge values which does not fit to any known data types because of it limitation?
If I was to do this in C (which I wouldn't: C++ is better for managing this sort of thing, IMHO), I would use some form of data structure that is able to represent the range of integers you want. For example, a structure of the form
struct SomeType
{
    int x[2];
}
can probably store up to MAX_INT*MAX_INT distinct integers (where MAX_INT is the maximum value that can be stored in an integer). If you write a set of helper functions that allow you to manipulate such structures (eg add them, subtract them, multiply them, print them, etc etc) your problem will be solved. To store 500! you will probably need a VERY large structure, so will probably resort to a dynamically allocated array of int's (or unsigned's) in your structure, and your manipulation function will need to make the array grow as required.
grumpy is offline   Reply With Quote