Created
June 13, 2023 06:14
-
-
Save Blizzardo1/efefd115367260aae48fcf087206d41b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Numerics; | |
namespace FactorialExample; | |
internal static class Program | |
{ | |
private static BigInteger Factorial(int number) { | |
if (number == 0) return 1; | |
return number * Factorial(number - 1); | |
} | |
private static void Main(string[] args) | |
{ | |
Console.Write("Please enter a number greater than zero: "); | |
if(!int.TryParse(Console.ReadLine(), out int number)) | |
{ | |
Console.WriteLine("Not a valid number!"); | |
return; | |
} | |
BigInteger factorial = Factorial(number); | |
Console.WriteLine($"The Factorial of {number} is {factorial}."); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment