Initial commit

This commit is contained in:
Mark J Price 2022-08-12 15:03:16 +01:00
parent b92b5a8e11
commit 82d7a2990d
2 changed files with 16 additions and 8 deletions

View file

@ -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}.");
}
}
}

View file

@ -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}.");
}
}
}