-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFactorial.cs
37 lines (28 loc) · 921 Bytes
/
Factorial.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
using System;
using AlgorithmsLibrary.AlgorithmsCore;
namespace AlgorithmsLibrary.Algorithms
{
internal class Factorial : Algorithm
{
public override string Description { get { return "Factorial calculator"; } }
private UInt64 Calculate(int amount)
{
UInt64 longAmount = (UInt64)amount;
if (amount <= 0) return 1;
else return longAmount * Calculate(amount - 1);
}
public override void Display()
{
int quanity;
Console.Write("What factorial do you want to display: ");
string input = Console.ReadLine();
bool isNumber = IntParseTestWithOutput(input);
if (!isNumber)
{
return;
}
quanity = int.Parse(input);
Console.Write("Factorial of " + quanity + ": " + Calculate(quanity));
}
}
}