v long integers, fractions

hello, I just started learning c++.

As a starting example I wanted to calculate n! of some integer n.
Unfortunately factorials get very large even for small n. All the variable types are not able to store the solution correctly. What should I do? Store the answer as a string or array and do the multiplications manually somehow?


If I want to use fractions instead of double can I include some header file which allows me do that? It shouldnt be too difficult to write sth that can do the basic operations with fractions but do I always have to write everything? With Math.h header I get some functions for example and I do not need to know how they exactly get their values.
There are libraries that allow you to work with numbers of arbitrary precision, most notably GMP:
http://gmplib.org/

There are classes for working with fractions as well, such as Boost.Rational:
http://www.boost.org/doc/libs/1_45_0/libs/rational/index.html
n factorial you mean?
You might be able to get more precision by using a "long long" in place of an "int". It depends on your compiler.
thank you athar, thats what I was looking for, now I have to find out how I get it to work.
mathhead, yes i ment n factorial. yes long long int is a little better.
Topic archived. No new replies allowed.