1: /// -------- ToujoursEnBeta
2: /// Author & Copyright : Peter Luschny
3: /// License: LGPL version 3.0 or (at your option)
4: /// Creative Commons Attribution-ShareAlike 3.0
5: /// Comments mail to: peter(at)luschny.de
6: /// Created: 2010-03-01
7:
8: namespace Sharith.Math.Factorial
9: {
10: using XInt = Sharith.Arithmetic.XInt;
11:
12: public class ProductNaive : IFactorialFunction
13: {
14: public ProductNaive() { }
15:
16: public string Name
17: {
18: get { return "ProductNaive "; }
19: }
20:
21: public XInt Factorial(int n)
22: {
23: if (n < 0)
24: {
25: throw new System.ArgumentOutOfRangeException("n",
26: Name + ": n >= 0 required, but was " + n);
27: }
28:
29: XInt nFact = XInt.One;
30:
31: for (int i = 2; i <= n; i++)
32: {
33: nFact *= i;
34: }
35: return nFact;
36: }
37: }
38: } // endOfProductNaive