13,894,085 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)
{
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: 18-Mar-19 7:37     Last Update: 18-Mar-19 7:37 Refresh 1