13,904,766 members
Alternative Tip/Trick
alternative version

#### Stats

8.7K views
1 bookmarked
Posted 4 Oct 2011
Licenced CPOL

# Calculate the Factorial of an Integer in C#

, 4 Oct 2011
Recursion is a neat way of calculating a number's factorial but there is a danger of the stack overflowing when the number is large. The following is a simplified version of the original. It obviates the need for the if else statements within the where loop.int Factorial(int input){ int...
Recursion is a neat way of calculating a number's factorial but there is a danger of the stack overflowing when the number is large. The following is a simplified version of the original. It obviates the need for the `if else` statements within the `where` loop.
```int Factorial(int input)
{
int answer = 0;
if (input > 0)
{
int count = input;
int answer = 1;
while (count > 1)
{
count--;
}
}
else
{
MessageBox.Show("Please enter only a positive integer.");
}

}```

## About the Author

 Student Wales
No Biography provided

## Comments and Discussions

 First Prev Next
 I like this solution. mcjohnson4-Oct-11 12:32 mcjohnson 4-Oct-11 12:32
 Updated to reflect updates to original Chris Maunder4-Oct-11 2:51 Chris Maunder 4-Oct-11 2:51
 Last Visit: 26-Mar-19 8:07     Last Update: 26-Mar-19 8:07 Refresh 1

General    News    Suggestion    Question    Bug    Answer    Joke    Praise    Rant    Admin

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.