Hi all,
How i do the factorial very large number in c++ ..Please give me sugestion and code
thanks in advance
Hi all,
How i do the factorial very large number in c++ ..Please give me sugestion and code
thanks in advance
Do not ask for code. Suggestions are fine. I would suggest using a 256-base system and store the digits in an std::string. Make this into a class with all the normal arithmetic operators defined. Next add a function called factorial (or maybe overload the ! operator?) and write the traditional factorial code there.
Hi all,
How i do the factorial very large number in c++ ..Please give me sugestion and code
thanks in advance
for very parge numbers, you should probably be using the GMP library for "bigint" types of numbers. those are not standard typews of integers, but are arrays of unsigned integers and one bit as the simulation of a sign bit where mathematical operations are done to simulate that the array is one large integer.
if you have ever done binary to hexadecimal conversion, it is the same type of math - the digits in each position are essentially like an unsigned integer in the array. got it? now you can make a class which does this called bigint. the tough part is going to be I/O, you are going to have to figure that part out. use your head.
by the way, there is a "bitset" collection template type in the standard c++ library which may prove useful - and there is a dynamic bitset type in Boost. but the types of math ops available aren't too promising.
if you don't want to go in any of these directions, use the type
long long
or
__int64 (microsoft and embarcadero compilers)
or
#include <_mingw.h>
__int64
or
#include <tr1/stdint.h>
uint64_t or int64_t (sorry, no 128-bit types yet)
use cout or printf("%I64u"...) or printf("%I64d"...)