Thread: Factorial 100!

  1. #1
    C is Sea. I know a drop! ganesh bala's Avatar
    Join Date
    Jan 2009
    Location
    Bangalore
    Posts
    58

    Unhappy Factorial 100!

    How can i find factorial of 100! ?

    Code:
          >> which data type can i use?.
          >> I didnt get answer even i used double,long double data type.

  2. #2
    Banned ಠ_ಠ's Avatar
    Join Date
    Mar 2009
    Posts
    687
    the factorial of 100 or the factorial of 100!?
    according to my calculator, the factorial of 100 is 9.33x10^157, which requires an unsigned integer of 525 bits (66 bytes) to hold it

    my calculator claims that the factorial of 100! is infinity
    Last edited by ಠ_ಠ; 06-23-2009 at 11:30 PM.
    ╔╗╔══╦╗
    ║║║╔╗║║
    ║╚╣╚╝║╚╗
    ╚═╩══╩═╝

  3. #3
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    >> which data type can i use?.

    There is no way you're going to fit that number into a standard data type. You could use a large array of bytes and treat it as a "big integer".
    Code:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

  4. #4
    The superhaterodyne twomers's Avatar
    Join Date
    Dec 2005
    Location
    Ireland
    Posts
    2,273
    Though ... post #2 gave you the answer so you don't need to do it anymore. It's 9.33x10^157.

  5. #5
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    - use your head to think about the problem in detail, rather than just writing the obvious for loop to do all the work
    - use a bignum library like this -> The GNU MP Bignum Library
    - write your own bignum functions sufficient to solve the problem.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  6. #6
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,318
    Quote Originally Posted by ಠ_ಠ View Post
    the factorial of 100 or the factorial of 100!?
    according to my calculator, the factorial of 100 is 9.33x10^157, which requires an unsigned integer of 525 bits (66 bytes) to hold it

    my calculator claims that the factorial of 100! is infinity
    The factorial of even 1 billion is larger than most computer's memories.

    ganesh bala: Why do you want to know how it can be done?
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. char Handling, probably typical newbie stuff
    By Neolyth in forum C Programming
    Replies: 16
    Last Post: 06-21-2009, 04:05 AM
  2. I just inherited a laptop and got some questions
    By DavidP in forum Tech Board
    Replies: 7
    Last Post: 08-16-2008, 12:42 PM
  3. Recursion
    By Lionmane in forum C Programming
    Replies: 11
    Last Post: 06-04-2005, 12:00 AM
  4. socket question
    By Unregistered in forum C Programming
    Replies: 3
    Last Post: 07-19-2002, 01:54 PM
  5. Unconvertable?
    By Unregistered in forum C++ Programming
    Replies: 3
    Last Post: 04-02-2002, 08:10 PM