Calculate factorials in C#

后端 未结 10 1821
日久生厌
日久生厌 2020-12-10 12:10

How can you calculate large factorials using C#? Windows calculator in Win 7 overflows at Factorial (3500). As a programming and mathematical question I am interested in kno

10条回答
  •  借酒劲吻你
    2020-12-10 12:16

    You will probably have to implement your own arbitrary precision numeric type.

    There are various approaches. probably not the most efficient, but perhaps the simplest is to have variable length arrays of byte (unsigned char). Each element represents a digit. ideally this would be included in a class, and you can then add a method which let's you multiply the number with another arbitrary precision number. A multiply with a standard C# integer would probably also be a good idea, but a little trickier to implement.

提交回复
热议问题