mirror of
https://github.com/markjprice/cs11dotnet7.git
synced 2026-03-28 15:24:37 +01:00
Initial commit
This commit is contained in:
parent
b92b5a8e11
commit
82d7a2990d
|
|
@ -97,8 +97,8 @@
|
|||
if (number < 0)
|
||||
{
|
||||
throw new ArgumentException(message:
|
||||
"The factorial function is defined for non-negative integers only.",
|
||||
paramName: "number");
|
||||
$"The factorial function is defined for non-negative integers only. Input: {number}",
|
||||
paramName: nameof(number));
|
||||
}
|
||||
else if (number == 0)
|
||||
{
|
||||
|
|
@ -115,16 +115,20 @@
|
|||
|
||||
static void RunFactorial()
|
||||
{
|
||||
for (int i = 1; i <= 14; i++)
|
||||
for (int i = -2; i <= 14; i++)
|
||||
{
|
||||
try
|
||||
{
|
||||
WriteLine($"{i}! = {Factorial(i):N0}");
|
||||
}
|
||||
catch (System.OverflowException)
|
||||
catch (OverflowException)
|
||||
{
|
||||
WriteLine($"{i}! is too big for a 32-bit integer.");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
WriteLine($"{ex.GetType()}: {ex.Message}.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -97,8 +97,8 @@
|
|||
if (number < 0)
|
||||
{
|
||||
throw new ArgumentException(message:
|
||||
"The factorial function is defined for non-negative integers only.",
|
||||
paramName: "number");
|
||||
$"The factorial function is defined for non-negative integers only. Input: {number}",
|
||||
paramName: nameof(number));
|
||||
}
|
||||
else if (number == 0)
|
||||
{
|
||||
|
|
@ -115,16 +115,20 @@
|
|||
|
||||
static void RunFactorial()
|
||||
{
|
||||
for (int i = 1; i <= 14; i++)
|
||||
for (int i = -2; i <= 14; i++)
|
||||
{
|
||||
try
|
||||
{
|
||||
WriteLine($"{i}! = {Factorial(i):N0}");
|
||||
}
|
||||
catch (System.OverflowException)
|
||||
catch (OverflowException)
|
||||
{
|
||||
WriteLine($"{i}! is too big for a 32-bit integer.");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
WriteLine($"{ex.GetType()}: {ex.Message}.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue