Skip to content

Commit e471a30

Browse files
committed
Added class and test method for code challenge First Factorial.
1 parent b12f970 commit e471a30

File tree

5 files changed

+45
-2
lines changed

5 files changed

+45
-2
lines changed

Coderbyte_CSharp/1 Easy Challenges/EasyChallenges.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Alphabet Soup 02/10/2021 AlphabetSorter
66
ArithGeo 02/10/2021 MathSequence
77
Check Numbers 02/10/2021 NumberCheck
88
Find Intersection 02/11/2021 StringIntersection
9-
First Factorial
9+
First Factorial 02/21/2021 Factorial
1010
First Reverse
1111
Letter Capitalize
1212
Letter Changes
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
7+
namespace Coderbyte_CSharp.Easy_Challenges
8+
{
9+
class Factorial
10+
{
11+
// Have the function FirstFactorial(num) take the num parameter being passed and
12+
// return the factorial of it. For example: if num = 4, then your program should
13+
// return (4 * 3 * 2 * 1) = 24. For the test cases, the range will be between 1
14+
// and 18 and the input will always be an integer.
15+
public ulong FirstFactorial(int num)
16+
{
17+
ulong factorial = (ulong)num;
18+
19+
for (int index = num - 1; index > 1; index--)
20+
{
21+
factorial *= (ulong)index;
22+
}
23+
24+
return factorial;
25+
}
26+
}
27+
}

Coderbyte_CSharp/Coderbyte_CSharp.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
</ItemGroup>
4545
<ItemGroup>
4646
<Compile Include="1 Easy Challenges\AlphabetSorter.cs" />
47+
<Compile Include="1 Easy Challenges\Factorial.cs" />
4748
<Compile Include="1 Easy Challenges\MathSequence.cs" />
4849
<Compile Include="1 Easy Challenges\NumberCheck.cs" />
4950
<Compile Include="1 Easy Challenges\PalindromeChecker.cs" />

Coderbyte_CSharp/Program.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ static void Main(string[] args)
2222
tc.Test_Palindrome();
2323
tc.Test_NumberCheck();
2424
tc.Test_FindIntersection();
25+
tc.Test_FirstFactorial();
2526

2627
// Medium
2728
tc.Test_Consecutive();

Coderbyte_CSharp/TestChallenge.cs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ public void Test_NumberCheck()
139139
Console.WriteLine();
140140
}
141141

142-
public void Test_FindIntersection()
142+
public void Test_FindIntersection()
143143
{
144144
string[] strArr = new string[2];
145145
string one = "3, 4, 7, 11, 21";
@@ -156,6 +156,19 @@ public void Test_FindIntersection()
156156

157157
Console.WriteLine();
158158
}
159+
160+
public void Test_FirstFactorial()
161+
{
162+
int num = 18;
163+
164+
Factorial compute = new Factorial();
165+
166+
Console.WriteLine("First Factorial:");
167+
168+
Console.WriteLine("Input: {0}", num);
169+
Console.WriteLine("Output: {0}", compute.FirstFactorial(num));
170+
Console.WriteLine();
171+
}
159172
#endregion
160173

161174
#region Medium Challenges
@@ -329,6 +342,7 @@ public void Test_Determinant()
329342
string[] array = new string[] { "1", "4", "3", "<>", "2", "3", "0", "<>", "5", "-3", "4" };
330343
int det;
331344

345+
Console.WriteLine("Matrix Determinant:");
332346
det = d.MatrixDeterminant(array, array.Length);
333347
PrintArray(array, array.Length);
334348
Console.WriteLine("Output: {0}", d.MatrixDeterminant(array, array.Length));

0 commit comments

Comments
 (0)