A Collection of Code Snippets in as Many Programming Languages as Possible
This project is maintained by TheRenegadeCoder
Welcome to the Factorial in C# page! Here, you'll find the source code for this program as well as a description of how the program works.
using System;
using System.Numerics;
namespace SamplePrograms
{
public class Factorial
{
public static BigInteger Fact(BigInteger n)
{
if (n <= 0)
return 1;
return n * Fact(n - 1);
}
public static void Main(string[] args)
{
try
{
var n = BigInteger.Parse(args[0]);
if (n > 4550)
{
Console.WriteLine(string.Format("{0}! is out of the reasonable bounds for calculation.", n));
Environment.Exit(1);
}
else if (n < 0) {
Console.WriteLine("Usage: please input a non-negative integer");
Environment.Exit(1);
}
var result = Fact(n);
Console.WriteLine(result);
}
catch
{
Console.WriteLine("Usage: please input a non-negative integer");
Environment.Exit(1);
}
}
}
}
Factorial in C# was written by:
If you see anything you'd like to change or update, please consider contributing.
No 'How to Implement the Solution' section available. Please consider contributing.
No 'How to Run the Solution' section available. Please consider contributing.