Skip to content

Commit

Permalink
Added Solution
Browse files Browse the repository at this point in the history
 Added Solution for Problem 20
  • Loading branch information
Thejus-Paul committed Nov 27, 2017
1 parent c787a22 commit 0337441
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
27 changes: 27 additions & 0 deletions Project Euler/Problem 20/sol1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Finding the factorial.
def factorial(n):
fact = 1
for i in range(1,n+1):
fact *= i
return fact

# Spliting the digits and adding it.
def split_and_add(number):
sum_of_digits = 0
while(number>0):
last_digit = number % 10
sum_of_digits += last_digit
number = int(number/10) # Removing the last_digit from the given number.
return sum_of_digits

# Taking the user input.
number = int(input("Enter the Number: "))

# Assigning the factorial from the factorial function.
factorial = factorial(number)

# Spliting and adding the factorial into answer.
answer = split_and_add(factorial)

# Printing the answer.
print(answer)
4 changes: 4 additions & 0 deletions Project Euler/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,7 @@ PROBLEMS:

16. 2^15 = 32768 and the sum of its digits is 3 + 2 + 7 + 6 + 8 = 26.
What is the sum of the digits of the number 2^1000?
20. 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!

0 comments on commit 0337441

Please sign in to comment.