Geeks With Blogs

News

This was probably one of the easiest ones to complete – a quick bash got me the following…

### The Problem

n! means n (n 1) ... 3 2 1

For example, 10! = 10 9 ... 3 2 1 = 3628800,
and the sum of the digits in the number 10! is 3 + 6 + 2 + 8 + 8 + 0 + 0 = 27.

Find the sum of the digits in the number 100!

### The Solution

```private static BigInteger Factorial(int num)
{
if (num > 1) return (BigInteger)num * Factorial(num - 1);
else return 1;
}

private static BigInteger SumDigits(string digits)
{
BigInteger result = 0;
foreach (char number in digits)
{
result += Convert.ToInt32(number)-48;
}
return result;
}```

```static void Main(string[] args)
{
Console.WriteLine(SumDigits(Factorial(100).ToString()));
Console.ReadLine();
}```
Posted on Friday, June 17, 2011 5:22 PM C# , Euler | Back to top

Related Posts on Geeks With Blogs Matching Categories

Comments on this post: Euler Problem 20

No comments posted yet.
Your comment:
(will show your gravatar)

Popular Posts on Geeks with Blogs 0
Geeks With Blogs Content Categories ASP.Net SQL Server Apple Google SharePoint Windows Visual Studio Team Foundation Server Agile Office Design Patterns Web Azure
Brand New Posts on Geeks with Blogs 0