Handling Exception using Factorial
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplicationSample
{
class Program3
{
public static void Main()
{
try
{
Console.WriteLine("The
factorial of 4 is: {0}\n",
Factorial(4));
}
catch (Exception)
{
//handle
exception here
}
Console.ReadLine();
}
static long Factorial(long number)
{
long FinalNumber = 1;
for (int i = 1; i <= number; i++)
{
FinalNumber = FinalNumber * i;
}
return FinalNumber;
}
}
}
0 comments
Post a Comment