Project Euler – Problem 20


Find the sum of digits in 100!

Problem:
n! means n × (n − 1) × … × 3 × 2 × 1

Find the sum of the digits in the number 100!

My Solution:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Euler
{
    class Problem20 : IProblemBase
    {

        //n! means n × (n ? 1) × ... × 3 × 2 × 1

        //Find the sum of the digits in the number 100!

        public Problem20()
        {
        }

        public string GetAnswer()
        {
            string result = "1";
            int ret = 0;
            long limit = 100;

            List<long> ul = new List<long>();

            for (long i = 1; i <= limit; i++)
            {
                result  = Util.BigMulitply(result,i.ToString());

            }

            char[] c = result.ToString().ToCharArray();
            for (int j = 0; j < c.Length; j++)
            {
                ret += Int32.Parse(c[j].ToString());

            }

            return ret.ToString(); ;

        }

    }
}
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: