Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Calculate factorial of any number less than 10000,but I don't know how to start with?

Calculate factorial of any number less than 10000,but I don't know how to start with?

Scheduled Pinned Locked Moved C / C++ / MFC
csstutorialquestion
9 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    milestanley
    wrote on last edited by
    #1

    Calculate factorial of any number less than 10000,but I don't know how to start with? I just want to get an idea, not the source code.

    R CPalliniC D M 5 Replies Last reply
    0
    • M milestanley

      Calculate factorial of any number less than 10000,but I don't know how to start with? I just want to get an idea, not the source code.

      R Offline
      R Offline
      Rajesh R Subramanian
      wrote on last edited by
      #2

      forPower wrote:

      Calculate factorial of any number less than 10000

      That's a big number to find the factorial of! You won't be able to do it with the existing datatypes, and normal arithmetic techniques. But you could use something like the BigNum[^] library. It is an excellent library and has been around for a while. FYI, I just calculated the factorial of 10000 online (using BigNum) and the answer is: here[^]

      forPower wrote:

      I just want to get an idea, not the source code.

      FYI, BigNum is free of cost and open source (LGPL).

      “Follow your bliss.” – Joseph Campbell

      1 Reply Last reply
      0
      • M milestanley

        Calculate factorial of any number less than 10000,but I don't know how to start with? I just want to get an idea, not the source code.

        CPalliniC Offline
        CPalliniC Offline
        CPallini
        wrote on last edited by
        #3

        Start making space for a lot of digits... :rolleyes:

        If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
        This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
        [My articles]

        In testa che avete, signor di Ceprano?

        1 Reply Last reply
        0
        • M milestanley

          Calculate factorial of any number less than 10000,but I don't know how to start with? I just want to get an idea, not the source code.

          CPalliniC Offline
          CPalliniC Offline
          CPallini
          wrote on last edited by
          #4

          forPower wrote:

          Calculate factorial of any number less than 10000,but I don't know how to start with?

          Start with 1!. :-D With standard C, using an (or two three... :rolleyes: ) array of (circa) 40000 unsigned chars you may roll you own-hand-crafted computation, anyway I doubt the output will be produced in 1 ms... :)

          If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
          This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
          [My articles]

          modified on Friday, October 16, 2009 5:16 AM

          In testa che avete, signor di Ceprano?

          1 Reply Last reply
          0
          • M milestanley

            Calculate factorial of any number less than 10000,but I don't know how to start with? I just want to get an idea, not the source code.

            D Offline
            D Offline
            David Crow
            wrote on last edited by
            #5

            Can you calculate factorials on paper? Until you get that much squared away, trying to write code is just going to get in your way.

            "Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown

            "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

            1 Reply Last reply
            0
            • M milestanley

              Calculate factorial of any number less than 10000,but I don't know how to start with? I just want to get an idea, not the source code.

              M Offline
              M Offline
              Maximilien
              wrote on last edited by
              #6

              0- do you know what a factorial is ? 0.5- did you google/bing about that ? 1- do you know how to calculate factorial on paper ? 2- can you translate that into code ? 2.5- did you even try something ? anyway, don't use recursion.

              This signature was proudly tested on animals.

              R 1 Reply Last reply
              0
              • M Maximilien

                0- do you know what a factorial is ? 0.5- did you google/bing about that ? 1- do you know how to calculate factorial on paper ? 2- can you translate that into code ? 2.5- did you even try something ? anyway, don't use recursion.

                This signature was proudly tested on animals.

                R Offline
                R Offline
                Rajesh R Subramanian
                wrote on last edited by
                #7

                Maximilien wrote:

                2- can you translate that into code ? 2.5- did you even try something ?

                Unfortunately I think that in this specific case, just translating the factorial logic into code simply won't work. If we use the datatypes that are available to us, and assuming that we use a 64 bit unsigned integer, the largest number that it can hold would be barely sufficient to hold the value of 20 factorial. For holding the resultant value of the computation of 40 factorial, there are no datatypes offered by the tools and languages used usually (it would be larger than what an 128 bit integer can hold!) And the OP wants to find the factorial of not 40, but the factorial of *cough* 10000. The way I know of is to use arbitrary precision arithmetic and the OP didn't know it. He just wanted to know how to get started with it. However, I do agree with you that he could have done a bit of Googling around.

                “Follow your bliss.” – Joseph Campbell

                M 1 Reply Last reply
                0
                • R Rajesh R Subramanian

                  Maximilien wrote:

                  2- can you translate that into code ? 2.5- did you even try something ?

                  Unfortunately I think that in this specific case, just translating the factorial logic into code simply won't work. If we use the datatypes that are available to us, and assuming that we use a 64 bit unsigned integer, the largest number that it can hold would be barely sufficient to hold the value of 20 factorial. For holding the resultant value of the computation of 40 factorial, there are no datatypes offered by the tools and languages used usually (it would be larger than what an 128 bit integer can hold!) And the OP wants to find the factorial of not 40, but the factorial of *cough* 10000. The way I know of is to use arbitrary precision arithmetic and the OP didn't know it. He just wanted to know how to get started with it. However, I do agree with you that he could have done a bit of Googling around.

                  “Follow your bliss.” – Joseph Campbell

                  M Offline
                  M Offline
                  Maximilien
                  wrote on last edited by
                  #8

                  well, if the OP cannot even code a simple factorial for small numbers, then defining it for large numbers is secondary.

                  This signature was proudly tested on animals.

                  D 1 Reply Last reply
                  0
                  • M Maximilien

                    well, if the OP cannot even code a simple factorial for small numbers, then defining it for large numbers is secondary.

                    This signature was proudly tested on animals.

                    D Offline
                    D Offline
                    David Crow
                    wrote on last edited by
                    #9

                    Maximilien wrote:

                    well, if the OP cannot even code a simple factorial for small numbers...

                    That's what I inferred from his post, too.

                    "Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown

                    "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

                    1 Reply Last reply
                    0
                    Reply
                    • Reply as topic
                    Log in to reply
                    • Oldest to Newest
                    • Newest to Oldest
                    • Most Votes


                    • Login

                    • Don't have an account? Register

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • World
                    • Users
                    • Groups