13,095,921 members (55,453 online)
Alternative Tip/Trick
alternative version

#### Stats

6.9K views
1 bookmarked
Posted 4 Oct 2011

# Calculate the Factorial of an Integer in C#

, 4 Oct 2011
 Rate this:
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)
{
if (input > 0)
{
int count = input;
while (count > 1)
{
count--;
}
}
else
{
MessageBox.Show("Please enter only a positive integer.");
}

}```

## Share

 Student Wales
No Biography provided

## You may also be interested in...

 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: 31-Dec-99 18:00     Last Update: 23-Aug-17 1:03 Refresh 1