Skip to content

Commit

Permalink
UPDATE: Updated Number Operations(Added Calculate Factorial)
Browse files Browse the repository at this point in the history
  • Loading branch information
lexara-prime-ai committed Jul 19, 2023
1 parent 3f6041e commit 2d20c36
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 2 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/**/.vscode
/**/bin
/**/obj
14 changes: 14 additions & 0 deletions CS CHALLENGES.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.0.31903.59
MinimumVisualStudioVersion = 10.0.40219.1
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
30 changes: 28 additions & 2 deletions Number Operations/Program.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
namespace OPERATIONS
{
{
class NUMBER_OPERATIONS
{
static void Main()
{
/* PRINT ODD NUMBERS */
Console.WriteLine("Please provide a range: ");
Console.WriteLine("NUMBER OPERATIONS\n***Generate Odd Numbers***\nPlease provide a range: ");
GENERATE_ODD_NUMBERS();

Console.WriteLine("\nProceed to generate Even Numbers or press Ctrl + C to exit...");
Expand All @@ -19,6 +19,10 @@ static void Main()
/* PRINT FIZZ BUZZ SEQUENCE */
Console.WriteLine("\nPlease provide a range: ");
GENERATE_FIZZ_BUZZ_SEQUENCE();

/* CALCULATE FACTORIAL */
Console.WriteLine("Proceed to Calculate Factorial or press Ctrl + C to exit...");
FACTORIAL();
}

/* GET USER INPUT */
Expand Down Expand Up @@ -93,5 +97,27 @@ static void GENERATE_FIZZ_BUZZ_SEQUENCE()
}
}
}

/* CALCULATE FACTORIAL */
static void FACTORIAL()
{
// FORMULA: n! = n * (n-1)
int INPUT = Int32.Parse(Console.ReadLine());
/* CHECK IF INPUT IS A NEGATIVE VALUE */
if (INPUT < 0)
{
throw new Exception("Negative numbers are not allowed!");
}

/* INITIALIZE OUTPUT TO 1 SINCE 0! AND 1! ARE EQUAL TO 1 */
int OUTPUT = 1;

for (int index = 1; index <= INPUT; index++)
{
OUTPUT *= index;
}

Console.WriteLine($"FACTORIAL OF {INPUT}: {OUTPUT}");
}
}
}

0 comments on commit 2d20c36

Please sign in to comment.